【问题标题】:How do I solve this SOAP exception 'Unmarshalling Error'如何解决此 SOAP 异常“Unmarshalling Error”
【发布时间】:2017-01-15 01:13:42
【问题描述】:

我正在开发一个项目,我正在使用内部托管的 3rd 方应用程序的 SOAP API(BMC FootPrints Service Core)。我可以使用 PHP 调用 API,我的凭据很好,并且在一个特定的 API 方法中,我正在对 API 函数进行看起来像是有效的调用,但得到以下异常/错误:

SoapFault exception: [soap:Client] Unmarshalling Error: cvc-complex-type.2.4.b: The content of element 'ns1:runSearch' is not complete. One of '{runSearchRequest}' is expected

“需要 '{runSearchRequest}' 之一”部分的确切含义是什么?我不明白在向 API 发出的请求中还需要包含什么。

API 文档可在此处找到,具体而言,第 31 页指的是我尝试使用的 API 方法,在此屏幕截图中记录:image from PDF

我不会发布所有代码,只发布我尝试 API 方法的部分:

// array that will be used in the method call...
$searchFor = array(
    "_searchId"=>"11",  
);

try { 
    $response = $soapClient->__soapCall("runSearch", $searchFor);
    print_r($response);
} catch (SoapFault $exception) {  
      echo $exception;  
}  

我使用 SOAPUI 应用程序测试了方法调用,我能够看到结果/响应正常。

更新:添加 WSDL xml (sn-ps)...

我正在使用 WSDL,但它托管在我们的内部/本地网络上并且没有暴露在外部,这是 XML 的开头和来自该 WSDL 的 runSearch 类型:

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://externalapi.business.footprints.numarasoftware.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ExternalApiService" targetNamespace="http://externalapi.business.footprints.numarasoftware.com/">
<wsdl:types>
<schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://xxxxxxxxxxxxxxxxxxxx.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://www.w3.org/2001/XMLSchema">

<import namespace="xxxxxxxxxxxxxxxxxxxxxxxx" schemaLocation="http://xxxxxxxxxxxxxxxxxxxxxxxx:PORT/footprints/servicedesk/externalapisoap/ExternalApiServicePort?xsd=externalapiservices_schema.xsd"/>

</schema>
</wsdl:types>

...

<wsdl:message name="runSearch">
   <wsdl:part element="tns:runSearch" name="parameters">
   </wsdl:part>
</wsdl:message>

【问题讨论】:

    标签: php api soap soap-client


    【解决方案1】:

    错误表明您的runSearchReqeust 结构(即您的$searchFor)缺少信息。您提供的文档表明 runSearch() 调用的签名如下所示:

    runSearchResponse runSearch(runSearch $runSearch)
    

    此外,runSearch 数据类型将包含一个 RunSearchRequest 类型的字段。

    所以你需要一个包含元素'runSearchRequest'的数据结构,它本身就是另一个包含_searchId的数据结构

    试试:

    $searchFor = array(
      'runSearchRequest' => array(
        "_searchId" => "11",
      )
    );
    

    并将您的呼叫更改为:

    $response = $soapClient->runSearch($searchFor);
    

    或者:

    $response = $soapClient->__soapCall("runSearch", array($searchFor));
    

    这将产生一个与文档中的请求非常匹配的 SOAP XML 请求:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:ns1="http://externalapi.business.footprints.numarasoftware.com/">
    <SOAP-ENV:Body>
            <ns1:runSearch>
                <runSearchRequest>
                    <_searchId>11</_searchId>
                </runSearchRequest>
            </ns1:runSearch>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    【讨论】:

    • 谢谢@KrisPeeling - 我刚刚解决了这个问题,我已经更新了我原来帖子中的代码。我仍然得到相同的结果/异常消息,就好像结构中缺少某些东西一样。
    • 感谢您更改问题。我已经更新了我的答案,希望能帮助您克服错误。
    • 谢谢,我在尝试后得到的是“SoapFault 异常:[Client] SOAP-ERROR: Encoding: object has no 'runSearchRequest' property”
    • 如果您使用的是 WSDL 文件,但您没有指明使用,可能会发生这种情况。你在使用 WSDL 吗?你能链接到它吗?它将包含比图像更有用的信息。
    • 是的,我正在使用 WSDL,并将该 XML 文件的开头和 runSearch 节点添加到我的原始帖子中。
    【解决方案2】:

    Unmarshalling Error 发生的原因有两个:

    • Exception: Unmarshalling Error: null: 如果后面有key Spaces
    • Exception: Unmarshalling Error: For input string: "233,43":因为Amount必须是233.43

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2021-08-04
      • 1970-01-01
      相关资源
      最近更新 更多