c# - C# - 如何在 Amadeus API 上发送 SOAP 请求
问题描述
我最近才开始体验 Amadeus API,
我正在 C# 上开发 Web 服务并生成 SOAP 请求(包括标头)。当我发送请求时,我收到此错误,如下所示:
这是我生成的请求:
<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 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>
如果有人有同样的问题,我愿意帮忙
推荐阅读
- php - PHP + SQLite3 根据昵称获取页面
- ios - 使用委托方法到 poptoviewcontroller 的问题 | 斯威夫特 5
- android - 新版本的 android studio 中的 gradle build 失败
- java - Java 解析响应 URLConnection 标头值
- kernel - 通过虚拟地址获取心理地址的位置
- kubernetes - 使用 Minikube 的 Debian VM - 将 VM IP 路由到公开的服务
- c++ - C++中选择和迭代语句内的类型转换过程
- node.js - 在某些条件下使用 xmlbuilder 时,结束标记放错了位置
- python - 如何使用 selenium 在 li 中获取 a 标签
- jmeter - 如何并行运行线程