1

我正在尝试使用 PHP/SOAP 从 Web 服务获取数据,并且响应数据集始终为空。我认为问题在于我如何设置 dsParams 参数。

这是网络服务 URL

如果我使用 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):

  1. 即使您没有参数,您也必须传递一个包含一个已初始化表的数据集对象。

  2. 如果确实有参数,则该表中必须有两列名为“ParamName”和“ParamValue”。

  3. 每个参数应该是表中自己的行,其名称在第一列,值在第二列。

注意:我没有参数。

下面是我尝试处理此任务的多种方法之一的示例。这是我能得到的最接近的,不会出错。

$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>
4

0 回答 0