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

huangapple go评论78阅读模式
英文:

C# - How to send SOAP Request on Amadeus API

问题

I understand that you're experiencing issues with the Amadeus API and SOAP requests. It seems you've encountered a "soap message header incorrect" error. While your request works in SOAP UI, there may still be an issue.

Here's the translation of your provided information. If you have specific questions or need further assistance, please let me know:

你遇到了Amadeus API和SOAP请求的问题,似乎出现了“soap message header incorrect”错误。尽管你在SOAP UI中的请求有效,但可能仍然存在问题。

英文:

i'm just starting experience with Amadeus API recently,

I'm developing web service on C# and generate SOAP request (including header). When i send request i'm receiving this error as shown you below:

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

Here's my generated request:

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

I think my request is correct, because my request working on SOAP UI. And receiving this response

Response:

<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: I explored additional error as below

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

It gives me soap message header incorrect error. But my request is working from SOAP UI.

答案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请求:

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

如果有人遇到相同的问题,我愿意提供帮助。

英文:

i solved my problem, my HTTPWebRequest was incorrect.

Here's my correct code. webRequest.Headers.Add value should be same as SOAP request action value.

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

SOAP Request:

        &lt;add:Action xmlns:add=&quot;&quot;http://www.w3.org/2005/08/addressing&quot;&quot;&gt;http://webservices.amadeus.com/PNRRET_17_2_1A&lt;/add:Action&gt;

If anyone have same problem, i'm ready to help

huangapple
  • 本文由 发表于 2020年1月6日 16:30:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608864.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定