1, -6ren">
gpt4 book ai didi

PHP SoapClient 没有为所有元素添加命名空间

转载 作者:行者123 更新时间:2023-12-04 17:02:02 28 4
gpt4 key购买 nike

我正在使用带有 WSDL 的 PHP Soap 客户端来发送 SOAP 请求。
这就是我初始化 SoapClient 的方式:

$options = [
"trace" => 1,
"login" => "Universal API/uAPI3170205802-sdv3r34",
"password" => "U^#3@$dfw2",
"classmap" => [
"BookingDisplayRsp" => "BookingAirSegmentRsp"
],
];
$this->soapClient = new \SoapClient("BookingAirPnrElement.wsdl",$options);
$request = [
"BookingAirPnrElementReq" => [
"AuthorizedBy" => 'user',
"SessionKey" => 'e6a30377-0956-4ac4-947d-b4ccb6641629',
"BillingPointOfSaleInfo" => [
"OriginApplication" => "uAPI"
],
"AddAirPnrElement" => [
"LoyaltyCard" => [
"SupplierCode" => "DL",
"CardNumber" => "23434523"
]
],
"TargetBranch" => "P878183",
]
];

做 SOAP 请求:
 $response = $this->soapClient->__soapCall('service', $request);

我收到一个 SOAP 故障:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<SOAP:Fault>
<faultcode>Server.Data</faultcode>
<faultstring>Error unmarshalling message body: Expected " {http://www.travelport.com/schema/sharedBooking_v41_0}BookingAirPnrElementReq" end tag, found "AddAirPnrElement" start tag (line 21, col 25, in UTF-8)</faultstring>
<detail>
<common_v41_0:ErrorInfo xmlns:common_v41_0="http://www.travelport.com/schema/common_v41_0">
<common_v41_0:Code>1005</common_v41_0:Code>
<common_v41_0:Service>WEBSVC</common_v41_0:Service>
<common_v41_0:Type>Data</common_v41_0:Type>
<common_v41_0:Description>Unable to parse XML stream</common_v41_0:Description>
<common_v41_0:TransactionId>C42964360A07425CB318E5F570EEE3DC</common_v41_0:TransactionId>
</common_v41_0:ErrorInfo>
</detail>
</SOAP:Fault>
</SOAP:Body>

SoapClient 生成的 XML 请求:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.travelport.com/schema/common_v41_0" xmlns:ns2="http://www.travelport.com/schema/sharedBooking_v41_0">
<SOAP-ENV:Header>
<h:SessionContext xmlns:h="http://www.travelport.com/soa/common/security/SessionContext_v1" xmlns="http://www.travelport.com/soa/common/security/SessionContext_v1">
<SessTok id="9444dc84-87c9-4563-80ab-a5f6475bfbe9"/>
</h:SessionContext>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:BookingAirPnrElementReq AuthorizedBy="user" TargetBranch="P878183" SessionKey="9444dc84-87c9-4563-80ab-a5f6475bfbe9">
<ns1:BillingPointOfSaleInfo OriginApplication="uAPI"/>
<AddAirPnrElement>
<ns1:LoyaltyCard CardNumber="23434523" SupplierCode="DL"/>
</AddAirPnrElement>
</ns2:BookingAirPnrElementReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

正如你所看到的 AddAirPnrElement 元素没有对应于 xmlns.ns2"/http://www10x104567919 ns2 的命名空间 ns2"/http://40x104567920.

如果我手动将 ns2 命名空间添加到该元素 ( AddAirPnrElement ) 并在 SoapUI 中发送相同的 XML 请求,则一切正常。
所以问题是 Soap Client 没有为该属性设置命名空间。

这是 WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="SharedBookingService"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.travelport.com/service/sharedBooking_v41_0"
xmlns:ns1="http://www.travelport.com/schema/sharedBooking_v41_0"
xmlns:sc="http://www.travelport.com/soa/common/security/SessionContext_v1" targetNamespace="http://www.travelport.com/service/sharedBooking_v41_0">

<import namespace="http://www.travelport.com/service/sharedBooking_v41_0" location="SharedBookingAbstract.wsdl"/>

<binding name="BookingAirPnrElementBinding" type="tns:BookingAirPnrElementPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="service">
<soap:operation soapAction="https://americas.universal-api.travelport.com/B2BGateway/connect/uAPI/SharedBookingService"/>
<input>
<soap:header use="literal" part="sessionContext" message="tns:SessionContext"/>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="ErrorInfoMsg">
<soap:fault name="ErrorInfoMsg" use="literal"/>
</fault>
</operation>
</binding>

<service name="SharedBookingService">
<port name="BookingAirPnrElementPort" binding="tns:BookingAirPnrElementBinding">
<soap:address location="https://americas.universal-api.travelport.com/B2BGateway/connect/uAPI/SharedBookingService"/>
</port>
</service>
</definitions>

谁能帮我理解为什么 Soap Client 没有设置命名空间?

非常感谢。

最佳答案

在更仔细地分析导入到 WSDL 中的 XSD 文件后,我注意到缺少 elementFormDefault="合格"从架构属性。我将它添加到架构中

<xs:schema xmlns="http://www.travelport.com/schema/sharedBooking_v41_0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:common="http://www.travelport.com/schema/common_v41_0"
xmlns:air="http://www.travelport.com/schema/air_v41_0"
xmlns:hotel="http://www.travelport.com/schema/hotel_v41_0"
targetNamespace="http://www.travelport.com/schema/sharedBooking_v41_0"
elementFormDefault="qualified"

并且所有命名空间都出现在 XML 请求中。

关于PHP SoapClient 没有为所有元素添加命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47326729/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com