5

C# Code:

 public static void CallWebService(string XmlText)
        {
            try
            {
                var _url = "https://nodeD1.test.webservices.amadeus.com/1ASIWMLFPNP";// "https://noded1.test.webservices.amadeus.com/1asiwmlfpnp";
                var _action = "http://webservices.amadeus.com/fmptbq_14_3_1a";

                XmlDocument soapEnvelopeXml = CreateSoapEnvelope(XmlText);
                HttpWebRequest webRequest = CreateWebRequest(_url, _action);
                webRequest = InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

                // begin async call to web request.
                IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

                // suspend this thread until call is complete. You might want to
                // do something usefull here like update your UI.
                asyncResult.AsyncWaitHandle.WaitOne();

                // get the response from the completed web request.
                string soapResult;
                using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
                {
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        soapResult = rd.ReadToEnd();
                    }
                    Console.Write(soapResult);
                }
            }
            catch (WebException webex)
            {
                WebResponse errResp = webex.Response;
                using (Stream respStream = errResp.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(respStream);
                    string text = reader.ReadToEnd();


                }
            }
        }

        private static HttpWebRequest CreateWebRequest(string url, string action)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Headers.Add("SOAPAction", action);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }

        private static XmlDocument CreateSoapEnvelope(string XmlText)
        {
            XmlDocument soapEnvelopeDocument = new XmlDocument();
            soapEnvelopeDocument.LoadXml(string.Format(@"{0}",XmlText));
            return soapEnvelopeDocument;
        }

        private static HttpWebRequest InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
                return webRequest;
            }
        }

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://xml.amadeus.com/2010/06/Security_v1" xmlns:typ="http://xml.amadeus.com/2010/06/Types_v1" xmlns:iat="http://www.iata.org/IATA/2007/00/IATA2010.1" xmlns:app="http://xml.amadeus.com/2010/06/AppMdw_CommonTypes_v3" xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1" xmlns:ses="http://xml.amadeus.com/2010/06/Session_v3" xmlns:fmp="http://xml.amadeus.com/FMPTBQ_14_3_1A">
   <soapenv:Header>
    <add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">29e8e874-3033-dd52-6b75-a2da58e10291</add:MessageID>
    <add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/fmptbq_14_3_1A</add:Action>
    <add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://noded1.test.webservices.amadeus.com/1asiwmlfpnp</add:To>
    <link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1"/>
    <oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <oas:UsernameToken oas1:Id="UsernameToken-1" xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <oas:Username>WSPNPMLF</oas:Username>
            <oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">bTEzbk5LNElzZw==</oas:Nonce>
            <oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">5lkky7mUVRujQPg4blzfKi5dSyg=</oas:Password>
            <oas1:Created>2017-12-15T13:43:34:532Z</oas1:Created>
        </oas:UsernameToken>
    </oas:Security>
    <AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">
        <UserID AgentDutyCode="SU" POS_Type="1" PseudoCityCode="BLRVS32CY" RequestorType="U"/>
    </AMA_SecurityHostedUser>
</soapenv:Header>
   <soapenv:Body>
      <Fare_MasterPricerTravelBoardSearch>
  <numberOfUnit>
    <unitNumberDetail>
      <numberOfUnits>1</numberOfUnits>
      <typeOfUnit>PX</typeOfUnit>
    </unitNumberDetail>
    <unitNumberDetail>
      <numberOfUnits>250</numberOfUnits>
      <typeOfUnit>RC</typeOfUnit>
    </unitNumberDetail>
  </numberOfUnit>
  <paxReference>
    <ptc>ADT</ptc>
    <traveller>
      <ref>1</ref>
    </traveller>
  </paxReference>
  <fareOptions>
    <pricingTickInfo>
      <pricingTicketing>
        <priceType>RP</priceType>
        <priceType>RU</priceType>
        <priceType>TAC</priceType>
        <priceType>ET</priceType>
        </pricingTicketing>
    </pricingTickInfo>
  </fareOptions>
  <travelFlightInfo>
    <cabinId>
      <cabinQualifier>RC</cabinQualifier>
      <cabin>Y</cabin>
    </cabinId>
  </travelFlightInfo>
  <itinerary>
    <requestedSegmentRef>
      <segRef>1</segRef>
    </requestedSegmentRef>
    <departureLocalization>
      <depMultiCity>
        <locationId>DEL</locationId>
      </depMultiCity>
    </departureLocalization>
    <arrivalLocalization>
      <arrivalMultiCity>
        <locationId>BOM</locationId>
      </arrivalMultiCity>
    </arrivalLocalization>
    <timeDetails>
      <firstDateTimeDetail>
        <timeQualifier>TD</timeQualifier>
        <date>201217</date>
        <time>0000</time>
        <timeWindow></timeWindow>
      </firstDateTimeDetail>
    </timeDetails>
  </itinerary>
  <itinerary>
    <requestedSegmentRef>
      <segRef>1</segRef>
    </requestedSegmentRef>
    <departureLocalization>
      <depMultiCity>
        <locationId>BOM</locationId>
      </depMultiCity>
    </departureLocalization>
    <arrivalLocalization>
      <arrivalMultiCity>
        <locationId>DEL</locationId>
      </arrivalMultiCity>
    </arrivalLocalization>
    <timeDetails>
      <firstDateTimeDetail>
        <timeQualifier>TD</timeQualifier>
        <date>251217</date>
        <time>0000</time>
        <timeWindow></timeWindow>
      </firstDateTimeDetail>
    </timeDetails>
  </itinerary>
</Fare_MasterPricerTravelBoardSearch>
   </soapenv:Body>
</soapenv:Envelope>

Response:

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

When the same request is passed using SoapUI im getting response but when C# Code is used im getting the above response.. if any one have implemented Amadeus Soap4.0 API in C# please help.

Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62
  • Do you have to manually create the Soap envelope? If you could generate a proxy class from the WSDL, then you wouldn't have this problem. – dotnetdave82 Dec 15 '17 at 16:29
  • in the proxy class we dont have option for adding nonce token and password – Amarnath Balasubramanian Dec 18 '17 at 09:22
  • If I run your code, I get "A header representing a Message Addressing Property is not valid and the message cannot be processed", which is not the same error you describe in question. – Evk Dec 18 '17 at 11:27
  • I have tried your soap envelope in postman and received the following response: soap:Client 12|Presentation|soap message header incorrect SI:muxDZ2 it seems that your soap request is wrong. – Yasirmx Dec 18 '17 at 13:38
  • @Evk are you aware of amadeus? – Amarnath Balasubramanian Dec 18 '17 at 17:38
  • Nope, have no idea. But I know what SOAP is and other related things. So I ask what is the expected response since I have different error than you describe. – Evk Dec 18 '17 at 18:07
  • 3
    If it is working in SOAP UI and not in your code then I would suggest using a proxy such as Fiddler to check what SOAP UI is actually sending – ste-fu Dec 20 '17 at 10:09
  • @Amarnath what is the configuration parameters used call 'CallWebService' – sanjeewa Mar 26 '18 at 10:44
  • Have you got this sorted ? – kirushan Aug 03 '18 at 06:44

1 Answers1

0

Maybe you have setup SoapUI to perform additional actions on the request payload (thus the request is not the same) ?

I would advise to create a proxy class from the given WSDL. While this proxy class doesn't support Nonce by default, it's extensible. check out WCF: Adding Nonce to UsernameToken

Now the 12 error code you get could also derive from other things.... Like for example I don't see your <Session /> element there (unless this represents a stateless request?)

Jaguar
  • 5,929
  • 34
  • 48
  • Yes it is a stateless request, but how do we call the extension – Amarnath Balasubramanian Dec 21 '17 at 17:46
  • @AmarnathBalasubramanian if you follow the link, it leads to https://social.msdn.microsoft.com/Forums/vstudio/en-US/4df3354f-0627-42d9-b5fb-6e880b60f8ee/non-schema-compliant-wsse-username-token-created?forum=wcf which includes a sample implementation of what you are looking for. Search for the part that writes "CustomCredentials: ClientCredentials" – Jaguar Dec 22 '17 at 13:18