[英]ZF2 Soap Request - Send parameters
I am trying to send a SOAP request to a client's API endpoint.我正在尝试向客户端的 API 端点发送 SOAP 请求。 I am not at all familiar with SOAP, so having quite a difficult time getting this to work.
我对 SOAP 一点也不熟悉,所以很难让它发挥作用。
From the client's documentation来自客户的文档
The requested ticket can be used to call all the API web methods subsequently.
public string RequestTicket(
string username,
string password
);
URL
https://www.clientsurl.net/api/v01_00/APIService.asmx?wsdl
Parameters
string username
string password
I am able to create the WSDL我能够创建 WSDL
$client = new Client('https://www.clientsurl.ca/api/v01_00/APIService.asmx?wsdl', ['soap_version' => SOAP_1_1]);
but not sure how to send the parameters through但不确定如何通过发送参数
$params = [
'username' => 'myusername'
'password' => 'mypassword'
];
I am also not sure what the relevance of RequestTicket
is.我也不确定
RequestTicket
的相关性是什么。 Am I supposed to add it to the url?我应该将它添加到网址吗?
The answer is probably very simple, but after tons of searching I couldn't find anything.答案可能很简单,但经过大量搜索后,我什么也没找到。 Please help.
请帮忙。
I have write a method to send a request我写了一个方法来发送请求
protected function soapRequest(string $method, array $arguments)
{
try {
$client = new \Zend\Soap\Client($this->getWsdl(),
[
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_NONE
]);
$result = $client->{$method}($arguments);
return $result->return;
} catch (\SoapFault $s) {
...
} catch (\Exception $e) {
...
}
}
You must have a Soap method to send yours parameters.您必须有一个 Soap 方法来发送您的参数。 If you don't know the method name, I advise you to run SoapUI application, very useful for debugging soap requests.
如果您不知道方法名称,我建议您运行 SoapUI 应用程序,这对于调试soap 请求非常有用。
A SOAP service has a set of operations that you can call over the network. SOAP 服务具有一组可以通过网络调用的操作。 These operations can also have parameters.
这些操作也可以有参数。 Basically, it's just like calling a method with parameters in code just that the invocation happens over the network with the method name and parameters being marshaled into an XML that respects the rules of the SOAP protocol.
基本上,这就像在代码中调用带有参数的方法一样,调用发生在网络上,方法名称和参数被编组到遵守 SOAP 协议规则的 XML 中。
To call the SOAP service, you can either make a HTTP request of type POST to the service's endpoint (ie https://www.clientsurl.ca/api/v01_00/APIService.asmx
) or you can use a SOAP client.要调用 SOAP 服务,您可以向服务的端点(即
https://www.clientsurl.ca/api/v01_00/APIService.asmx
)发出 POST 类型的 HTTP 请求,也可以使用 SOAP 客户端。 A SOAP client is some code that you can generate from the WSDL of the SOAP web service, or is some code that can dynamically read the WSDL and provide you some ways to invoke the operations described there. SOAP 客户端是一些可以从 SOAP Web 服务的 WSDL 生成的代码,或者是一些可以动态读取 WSDL 并提供一些方法来调用其中描述的操作的代码。 As opposed to making a POST HTTP request, the client takes care of these details for you and allows you to make the call over the network just like you call a local method in your code.
与发出 POST HTTP 请求相反,客户端会为您处理这些细节,并允许您通过网络进行调用,就像您在代码中调用本地方法一样。
To call an operation of the SOAP service in your client code you have to invoke a method with parameters.要在客户端代码中调用 SOAP 服务的操作,您必须调用带参数的方法。 The name of the method and its parameters (what names and what types) are described by the WSDL of the service.
方法的名称及其参数(名称和类型)由服务的 WSDL 描述。
With that being said, I'll add some details about what you posted in your question.话虽如此,我将添加一些有关您在问题中发布的内容的详细信息。
The requested ticket can be used to call all the API web methods subsequently.
请求的票证可用于随后调用所有 API Web 方法。
Some service operations can require authentication in order to be be allowed to invoke them.某些服务操作可能需要身份验证才能被允许调用它们。 Just like you need a username and password to access protected sections of a website for example.
就像您需要用户名和密码来访问网站的受保护部分一样。 For a SOAP web service, his can happen in a few ways, the most common two being:
对于 SOAP Web 服务,他可以通过几种方式发生,最常见的两种是:
It seems that your service uses the second approach, and RequestTicket
seems to be the operation that you need to call in order to be able to call the rest of the operations after that.您的服务似乎使用了第二种方法,而
RequestTicket
似乎是您需要调用的操作,以便能够在此之后调用其余的操作。
I am able to create the WSDL
我能够创建 WSDL
You do not create the WSDL, the WSDL already exists for the web service.您没有创建 WSDL,Web 服务的 WSDL 已经存在。 Also make sure you do not make a confusion between the SOAP web service and its WSDL .
还要确保不要混淆 SOAP Web 服务和它的 WSDL 。 The code you show just creates a SOAP client from the WSDL (what I described above) to allow you to invoke operations on it.
您展示的代码只是从 WSDL(我上面描述的)创建了一个 SOAP 客户端,以允许您调用它的操作。
I am also not sure what the relevance of RequestTicket is.
我也不确定 RequestTicket 的相关性是什么。 Am I supposed to add it to the url?
我应该将它添加到网址吗?
Most likely RequestTicket
is an operation of the web service.最有可能的
RequestTicket
是 Web 服务的操作。 You should look inside the WSDL to see if it's described there.您应该查看 WSDL 内部是否有描述。 The WSDL is a little tough to swallow if you are not familiar with how it works, so your best bet is to use a tool like SoapUI to feed it the web service WSDL and have SoapUI generate sample requests for the web service.
如果您不熟悉 WSDL 是如何工作的,那么它有点难以接受,所以最好的办法是使用像SoapUI这样的工具为它提供 Web 服务 WSDL,并让 SoapUI 为 Web 服务生成示例请求。 You can then also use SoapUI to test the web service to make sure you understand how it works before you try to replicate the same calls with your PHP code.
然后,您还可以使用 SoapUI 来测试 Web 服务,以确保您在尝试使用 PHP 代码复制相同调用之前了解它的工作原理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.