php - 重新创建从 SoapUI 到 PHP 的工作 SOAP 请求

标签 php xml soap webservice-client

我已经在 PHP 中创建了一个登录的 soap 客户端,但是对于我想要发出的第二个请求,我似乎无法让 PHP 正确地构建请求。

这是在 SoapUI 中工作的请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://v1.productapi.gs1ca.org" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <v1:searchProducts>
         <sessionId>f53c5450-392e-4ca4-b592-adbb436cfe1f</sessionId>
         <searchCriteria>
            <v1:AttributeValue>
               <v1:attribute>dateupdated</v1:attribute>
               <v1:value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">08/01/2013</v1:value>
            </v1:AttributeValue>
<v1:AttributeValue>
               <v1:attribute>dateupdatedcompare</v1:attribute>
               <v1:value  i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">1</v1:value>
            </v1:AttributeValue>
         </searchCriteria>
         <includeImageAttributes>0</includeImageAttributes>
         <sortOrder>dateupdated</sortOrder>
      </v1:searchProducts>
   </soapenv:Body>
</soapenv:Envelope>

我如何使用 PHP 以与工作请求相同的方式格式化 XML?

已经取得了一些进展。

我现在已经能够重新创建 xml 了。请求看起来像这样:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://v1.productapi.gs1ca.org">
    <SOAP-ENV:Body>
        <ns1:searchProducts>
            <sessionId>2a7d0294-8d96-428d-abd8-08add9cfc427</sessionId>
            <searchCriteria>
                <ns1:AttributeValue>
                    <ns1:attribute>dateupdated</ns1:attribute>
                    <ns1:value>01/01/2013</ns1:value>
                </ns1:AttributeValue>
                <ns1:AttributeValue>
                    <ns1:attribute>dateupdatedcompare</ns1:attribute>
                    <ns1:value>1</ns1:value>
                </ns1:AttributeValue>
            </searchCriteria>
            <includeImageAttributes>false</includeImageAttributes>
            <sortOrder>dateupdated</sortOrder>
        </ns1:searchProducts>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

创建该请求的 PHP 是:

    $args0 = array(
        'sessionid'=>$session,
        'searchcriteria'=> array(array('attribute'=>'dateupdated','value'=>'01/01/2013'),array('attribute'=>'dateupdatedcompare','value'=>'1')),
        'includeimageattributes'=>0,
        'sortorder'=>'dateupdated');

$result = $client->__soapCall('searchProducts',$args0);

抛出的错误是:

Error: SoapFault exception: [a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://v1.productapi.gs1ca.org:searchCriteria. The InnerException message was 'Element value from namespace http://v1.productapi.gs1ca.org cannot have child contents to be deserialized as an object. Please use XmlNode[] to deserialize this pattern of XML.

我仍然缺少信封的一部分:

xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

我需要值标签看起来像这样:

<v1:value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">

关于如何添加这些部分有什么想法吗?

最佳答案

好的!我终于想通了。它很丑陋,但它有效。

   try {
        $args = array(
            'sessionid'=>$session,
            'searchcriteria'=> new SoapVar('<searchCriteria><ns1:AttributeValue>
                                                <ns1:attribute>dateupdated</ns1:attribute>
                                                <ns1:value xsi:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">01/01/2013</ns1:value>
                                            </ns1:AttributeValue>
                                            <ns1:AttributeValue>
                                                <ns1:attribute>dateupdatedcompare</ns1:attribute>
                                                <ns1:value xsi:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">1</ns1:value>
                                            </ns1:AttributeValue></searchCriteria>
                                            ', XSD_ANYXML, "http://www.w3.org/2001/XMLSchema-instance"),
            'includeimageattributes'=>0,
            'sortorder'=>'dateupdated');
    $result = $client->__soapCall('searchProducts',$args);
    } catch (SoapFault $e) {
        echo "Error: {$e}";
    }

关于php - 重新创建从 SoapUI 到 PHP 的工作 SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18382869/

相关文章:

php - 从 javascript OOP 背景理解 php 类结构(如何调整代码工作流程)

html - SQL Server HTML 正文电子邮件格式不正确(已添加 XML)

java - 在给定 WSDL 文件的情况下在 Java 中创建 SOAP 客户端

java - 选项卡的权限级别

php - 命令在 SSH 终端中有效,但在 PHP 脚本中无效

java - 对话框中的Viewpager?

JQuery、XML 和标签名称中的句点

soap - WSDL 中的 xmlns 不正确

soap - JAX-WS:尝试添加安全 header 时获取 DOMException - HIERARCHY_REQUEST_ERR

php - 如何在过程内部查询中使用过程参数变量