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

问题描述 投票:0回答:1

我最近刚开始体验Amadeus API。

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

My error

这是我生成的请求。

<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用户界面上工作。而收到的响应是

回应。

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

UPDATE: 我探索了额外的错误,如下

    <?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消息头不正确的错误。但我的请求在SOAP用户界面上可以工作。

更新2: 通过修改SOAP Action解决了这个错误。正确的代码作为答案发布。

c# soapui amadeus
1个回答
0
投票

我解决了我的问题,我的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请求.Headers.Add值应该和SOAP请求动作值一样。

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

如果有人有同样的问题,我愿意帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.