dszsajhd237437 2017-11-16 10:04
浏览 55

PHP SoapClient不会向所有元素添加命名空间

I'm using PHP Soap Client with WSDL to send soap requests. That's the way I initialize the 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",
    ]
];

Doing Soap Request:

 $response = $this->soapClient->__soapCall('service', $request);

I receive a Soap Fault:

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

The XML request generated by SoapClient:

<?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>

As you can see the AddAirPnrElement element does not have namespace ns2 that corresponds to the xmlns:ns2="http://www.travelport.com/schema/sharedBooking_v41_0"

If I add manually ns2 namespace to that element (AddAirPnrElement) and I send the same XML request in SoapUI, everything is ok. So the problem is that Soap Client does not set a namespace to that attribute.

Here is the 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>

Can anyone help me understand why Soap Client does not set the namespace?

Thanks a lot.

  • 写回答

1条回答 默认 最新

  • douhan9619 2017-11-16 20:17
    关注

    After analyzing more carefully the XSD file that was imported into WSDL, I noticed that is missing elementFormDefault="qualified" from schema attributes. I added it to the schema

    <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"
    

    and all the namespaces appeared in the XML request.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统