我正在尝试使用PHP / SOAP从Web Service获取数据,并且响应数据集始终为空。我相信这个问题在于我如何设置dsParams参数。
如果我使用SoapUI并发送此请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:max="http://www.maxhire.net/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soapenv:Header>
<max:AuthHeader>
<!--Optional:-->
<max:DatabaseName>Name</max:DatabaseName>
<!--Optional:-->
<max:SecurityKey>Key</max:SecurityKey>
</max:AuthHeader>
</soapenv:Header>
<soapenv:Body>
<max:ExecuteCustomStoredProcedureGetResults>
<max:strProcName>JobPostings</max:strProcName>
<max:dsParams>
<xs:schema id="NewDataSet" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="ParamName" type="xs:string" minOccurs="0"/>
<xs:element name="ParamValue" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</max:dsParams>
</max:ExecuteCustomStoredProcedureGetResults>
</soapenv:Body>
</soapenv:Envelope>
我得到了理想的结果。
使用SOAP调用的每个Web方法都必须传递适当的安全凭据。必须在SOAP标头中将这些凭据指定为DatabaseName和SecurityKey。这部分工作正常。
根据文件:
关于dsParams
有关dsParams数据集的一些注意事项,您必须传递这些数据集以使用这些函数中的任何一个(例如ExecuteCustomStoredProcedureGetResults ):
即使您没有参数,也必须传递包含一个已初始化的表格的数据集对象。
如果您有参数,则该表中必须有两列名为“ParamName”和“ParamValue”的列。
每个参数都应该是表中自己的行,其名称在第一列,值在第二列。
注意:我没有参数。
以下是我尝试接受此任务的众多方法之一的示例。这是我能得到的最接近的错误。
$client = new SoapClient('https://www.maxhire.net/MaxHireAPI/UserServices.asmx?wsdl',array('trace' => TRUE));
$header = new SoapHeader(
'http://www.maxhire.net/',
'AuthHeader',array(
'DatabaseName' => 'Name',
'SecurityKey' => 'Key'
),
false
);
$client->__setSoapHeaders($header);
try {
$jobs = new stdClass();
$jobs->strProcName = 'JobPostings';
$jobs->NewDataSet = new stdClass();
$jobs->NewDataSet->Table = new stdClass();
$jobs->NewDataSet->Table->ParamName = '';
$jobs->NewDataSet->Table->ParamValue = '';
$result = $client->ExecuteCustomStoredProcedureGetResults($jobs);
echo "<pre>\n";
var_dump($result);
echo "</pre>\n";
}
catch(SoapFault $soapfault){
echo "<pre>\n";
var_dump($soapfault);
echo "</pre>\n";
}
以下是我得到的回复:
object(stdClass)#7 (1) {
["ExecuteCustomStoredProcedureGetResultsResult"]=>
object(stdClass)#8 (2) {
["schema"]=>
string(323) "<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"><xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"/></xs:complexType></xs:element></xs:schema>"
["any"]=>
string(127) "<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"/>"
}
}
echo "Request:\n" . $client->__getLastRequest() . "<br />\n";
Request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.maxhire.net/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:DatabaseName>Name</ns1:DatabaseName>
<ns1:SecurityKey>Key</ns1:SecurityKey>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ExecuteCustomStoredProcedureGetResults>
<ns1:strProcName>JobPostings</ns1:strProcName>
</ns1:ExecuteCustomStoredProcedureGetResults>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
echo "Response:\n" . $client->__getLastResponse() . "<br />\n";
Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ExecuteCustomStoredProcedureGetResultsResponse xmlns="http://www.maxhire.net/">
<ExecuteCustomStoredProcedureGetResultsResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" />
</ExecuteCustomStoredProcedureGetResultsResult>
</ExecuteCustomStoredProcedureGetResultsResponse>
</soap:Body>
</soap:Envelope>