记录一下对接 soap 接口的一些疑问
网上查的90% 得文章都是对方只提供了一个接口地址。 我拿到文档时,里面标注了两个地址。知道是两个地址配合使用,但是一直找不到第二个在哪使用。
wsdl地址: 192.168.1.200/soap/xxx.xxx.cls?wsdl
服务地址: 192.168.1.200/soap/xxx.xxx.cls?CfgItem=JC0722
创建soap连接对象SoapClient(null|string $wsdl, array $options = null)
,该对象有两种模式进行连接:
- non-WSDL
- WSDL 模式客户端
non-WSDL
创建时,$wsdl 该参数为null, 需要在options中必须设置location 和uri
$client = new SoapClient(null, [
'location' => $location, // 发送请求的地址url
'uri' => $uri // soap 的命名空间
]);
WSDL 模式客户端
创建时,$wsdl 该参数为指定的wsdl 文件地址,options 可选参数详见这里
下面代码 注意__soapCall 的第三个参数。 location 设置具体的访问服务地址
$client = new SoapClient($wsdl, [
'soap_version' => SOAP_1_2, // 可选值:SOAP_1_1 or SOAP_1_2
'trace' => true, // 设置true 后,使用 $client->__getLastRequest() 查看请求报文
]);
// 这里主要看 __soapCall 的第三个参数。 location 设置具体的访问服务地址
$response = $client->__soapCall('Send', [$params], ['location' => $webServiceUrl]);
就是这句话,找了我大半天,之前是直接使用$client->function_name()
,一直报找不到服务。一直找第二个地址在哪里使用。纠结在new client
的时候把第二个uri放进去。诶,还是年轻
以下是一些可供调用的函数方法,常用的是获取方法名:__getFunctions(), 获取参数类型: __getTypes(), 获取请求参数,需要打开trace: __getLastRequest
SoapClient::__call — Calls a SOAP function (deprecated)
SoapClient::__construct — SoapClient constructor
SoapClient::__doRequest — Performs a SOAP request
SoapClient::__getCookies — Get list of cookies
SoapClient::__getFunctions — Returns list of available SOAP functions
SoapClient::__getLastRequest — Returns last SOAP request
SoapClient::__getLastRequestHeaders — Returns the SOAP headers from the last request
SoapClient::__getLastResponse — Returns last SOAP response
SoapClient::__getLastResponseHeaders — Returns the SOAP headers from the last response
SoapClient::__getTypes — Returns a list of SOAP types
SoapClient::__setCookie — Defines a cookie for SOAP requests
SoapClient::__setLocation — Sets the location of the Web service to use
SoapClient::__setSoapHeaders — Sets SOAP headers for subsequent calls
SoapClient::__soapCall — Calls a SOAP function