gpt4 book ai didi

c# - 在 C# 中使用 Amadeus Soap4.0

转载 作者:行者123 更新时间:2023-11-30 18:15:38 25 4
gpt4 key购买 nike

C#代码:

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

要求:

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

响应:

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

当使用 SoapUI 传递相同的请求时,我会收到响应,但是当使用 C# 代码时,我会收到上述响应。如果有人在 C# 中实现了 Amadeus Soap4.0 API,请提供帮助。

最佳答案

也许您已设置 SoapUI 以对请求负载执行其他操作(因此请求不相同)?

我建议从给定的 WSDL 创建一个代理类。虽然此代理类默认不支持 Nonce,但它是可扩展的。查看WCF: Adding Nonce to UsernameToken

现在你得到的 12 错误代码也可能来自其他东西......例如我没有看到你的 <Session />那里的元素(除非这代表无状态请求?)

关于c# - 在 C# 中使用 Amadeus Soap4.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47835957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com