C# - 如何在 Amadeus 上发送 SOAP 请求 API

C# - How to send SOAP Request on Amadeus API

我最近才开始体验 Amadeus API,

我在 C# 上开发 Web 服务并生成 SOAP 请求(包括 header)。当我发送请求时,我收到此错误,如下所示:

这是我生成的请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://xml.amadeus.com/2010/06/Security_v1" xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1" xmlns:ses="http://xml.amadeus.com/2010/06/Session_v3" xmlns:pnr="http://xml.amadeus.com/PNRRET_17_2_1A">
  <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <sec:AMA_SecurityHostedUser>
      <sec:UserID POS_Type="1" RequestorType="U" PseudoCityCode="***" AgentDutyCode="GS" />
    </sec:AMA_SecurityHostedUser>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <wsse:UsernameToken>
        <wsse:Username>***</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">***</wsse:Password>
        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">***</wsse:Nonce>
        <wsu:Created>2020-01-06T08:20:54.229Z</wsu:Created>
      </wsse:UsernameToken>
    </wsse:Security>
    <awsl:TransactionFlowLink xmlns:awsl="http://wsdl.amadeus.com/2010/06/ws/Link_v1">
      <awsl:Consumer>
        <awsl:UniqueID>***</awsl:UniqueID>
      </awsl:Consumer>
    </awsl:TransactionFlowLink>
    <wsa:Action soapenv:mustUnderstand="1">http://webservices.amadeus.com/PNRRET_17_2_1A</wsa:Action>
    <wsa:ReplyTo soapenv:mustUnderstand="1">
      <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
    </wsa:ReplyTo>
    <wsa:MessageID soapenv:mustUnderstand="1">a95b1dd9-bc66-4e45-b3b5-9856d26cf73d</wsa:MessageID>
    <wsa:To soapenv:mustUnderstand="1">https://nodea1.test.webservices.amadeus.com/1asiwgenom</wsa:To>
    <ses:Session TransactionStatusCode="Start" />
  </soapenv:Header>
  <soapenv:Body>
    <PNR_Retrieve>
      <retrievalFacts>
        <retrieve>
          <type>2</type>
        </retrieve>
        <reservationOrProfileIdentifier>
          <reservation>
            <controlNumber>KQLFMO</controlNumber>
          </reservation>
        </reservationOrProfileIdentifier>
      </retrievalFacts>
    </PNR_Retrieve>
  </soapenv:Body>
</soapenv:Envelope>

我认为我的请求是正确的,因为我的请求在 SOAP UI 上工作。并收到此回复

响应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:awsse="http://xml.amadeus.com/2010/06/Session_v3" xmlns:awsl="http://wsdl.amadeus.com/2010/06/ws/Link_v1" xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <soapenv:Header>
      <wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
      <wsa:From>
         <wsa:Address>https://nodea1.test.webservices.amadeus.com/1asiwgenom</wsa:Address>
      </wsa:From>
      <wsa:Action>http://webservices.amadeus.com/PNRRET_17_2_1A</wsa:Action>
      <wsa:MessageID>urn:uuid:1b0fa3e2-aeab-6c04-e51a-e58eea253740</wsa:MessageID>
      <wsa:RelatesTo RelationshipType="http://www.w3.org/2005/08/addressing/reply">a95b1dd9-bc66-4e45-b3b5-9856d26cf73d</wsa:RelatesTo>
      <awsl:TransactionFlowLink>
         <awsl:Consumer>
            <awsl:UniqueID>6G4ZNgagmREbd5+gDBX5UA==</awsl:UniqueID>
         </awsl:Consumer>
         <awsl:Receiver>
            <awsl:ServerID>urn:uuid:70a5c12d-315b-547f-9e5b-39df6437c2cb</awsl:ServerID>
         </awsl:Receiver>
      </awsl:TransactionFlowLink>
      <awsse:Session TransactionStatusCode="InSeries">
         <awsse:SessionId>00JOZSQJ2S</awsse:SessionId>
         <awsse:SequenceNumber>1</awsse:SequenceNumber>
         <awsse:SecurityToken>1GAA2YMB6MTOR1ZLRG5QLKPIEH</awsse:SecurityToken>
      </awsse:Session>
   </soapenv:Header>
   <soapenv:Body>
      <soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
         <faultcode>soap:Server</faultcode>
         <faultstring>1931|Application|NO MATCH FOR RECORD LOCATOR</faultstring>
         <faultactor>SI:Backend</faultactor>
      </soap:Fault>
   </soapenv:Body>
</soapenv:Envelope>

更新: 我探索了以下其他错误

    <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Client</faultcode>
            <faultstring>12|Presentation|soap message header incorrect</faultstring>
            <faultactor>SI:muxDZ2</faultactor>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

它给我 soap 消息 header 不正确的错误。但是我的请求是从 SOAP UI.

我解决了我的问题,我的 HTTPWebRequest 不正确。

这是我的正确代码。 webRequest.Headers.Add 值应与 SOAP 请求操作值相同。

        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
        webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
        webRequest.Headers.Add("SOAPAction:\"http://webservices.amadeus.com/PNRRET_17_2_1A\"");
        webRequest.ContentType = "text/xml; charset=utf-8";
        webRequest.Accept = "text/xml";
        webRequest.Method = "POST";
        return webRequest;

SOAP 请求:

        <add:Action xmlns:add=""http://www.w3.org/2005/08/addressing"">http://webservices.amadeus.com/PNRRET_17_2_1A</add:Action>

如果有人遇到同样的问题,我随时准备提供帮助