在.net 4.5中创建Sabre SOAP会话失败



我正在构建一个POC(windows项目),并试图调用sable会话创建请求。我已经获得了用于生成WSDL的sts-url,并且可以在Visual studio 2015中使用.net 4.5使用链接生成代理类http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl.现在我有了Sabre为我的公司提供的用户id和密码,我试着把它们放在请求中,就像帖子"使用.net消费Sabre soap服务"中建议的那样,但没有成功,因为代理类对象在新的CRT url调用服务时会抛出错误(https://sws-crt-as.cert.havail.sabre.com)佩剑。异常:"System.ServiceModel.Security.SecurityNegotiationException:无法为具有权限'sws crt as.cert.havai.sab.com'的SSL/TLS建立安全通道。--->System.Net.Web异常:请求已中止:无法创建SSL/TLS安全通道。".这里有任何内部异常(与外部异常的文本相同),它将异常的InternalSTatus属性指示为"RequestFatal"。这里提供app.config内容供参考,也提供

请帮我指出错误(可能在web.config/code中)

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SessBehavior">
<clientCredentials>
&lt;clientCertificate storeLocation="LocalMachine" storeName="TrustedPublisher" x509FindType="FindByThumbprint" findValue="E3FC0AD84F2F5A83ED6F86F567F8B14B40DCBF12" /><!--EV SSL CA G3-->
&lt;/clientCredentials>
&lt;/behavior>
&lt;/endpointBehaviors>
&lt;/behaviors>
&lt;bindings>
&lt;customBinding>
&lt;binding name="SessionCreateSoapBinding">
&lt;textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap11" writeEncoding="utf-8">
&lt;readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
&lt;/textMessageEncoding>
&lt;httpsTransport maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000" />
&lt;/binding>
&lt;/customBinding>
&lt;/bindings>
&lt;client>
&lt;endpoint address="https://sws-crt-as.cert.havail.sabre.com" 
behaviorConfiguration="SessBehavior"
binding="customBinding"
bindingConfiguration="SessionCreateSoapBinding" contract="SessionCreate.SessionCreatePortType"
name="SessionCreatePortType" />
&lt;/client>
&lt;/system.serviceModel>

创建会话的代码:

public SabreSessionInfo sabreCreateSession(string user, string pass, string pseudo, string org, bool doGetAirVendors)
{
SabreSessionInfo inf = new SabreSessionInfo();
try
{
string userName = user;
string password = pass;
string PCC = pseudo;
string domain = "LA";
DateTime dt = DateTime.UtcNow;
string tstamp = dt.ToString("s").Replace("-","").Replace(":","") + "Z";
SessionCreate.MessageHeader msgHeader = new SessionCreate.MessageHeader();
msgHeader.ConversationId = tstamp; 
SessionCreate.From from = new SessionCreate.From();
SessionCreate.PartyId fromPartyId = new SessionCreate.PartyId();
SessionCreate.PartyId[] fromPartyIdArr = new SessionCreate.PartyId[1];
fromPartyId.Value = "99999"; 
fromPartyIdArr[0] = fromPartyId;
from.PartyId = fromPartyIdArr;
msgHeader.From = from;
SessionCreate.To to = new SessionCreate.To();
SessionCreate.PartyId toPartyId = new SessionCreate.PartyId();
SessionCreate.PartyId[] toPartyIdArr = new SessionCreate.PartyId[1];
toPartyId.Value = "123123"; 
toPartyIdArr[0] = toPartyId;
to.PartyId = toPartyIdArr;
msgHeader.To = to;
//Add the value for eb:CPAId, which is the IPCC. 
//Add the value for the action code of this Web service, SessionCreateRQ.
msgHeader.CPAId = "AnyCPA";
msgHeader.Action = "SessionCreateRQ";// Web method name
SessionCreate.Service service = new SessionCreate.Service();
service.Value = "Session";
msgHeader.Service = service;
SessionCreate.MessageData msgData = new SessionCreate.MessageData();
msgData.MessageId = "mid:" + tstamp + "@clientofsabre.com";
msgData.Timestamp = tstamp;
msgHeader.MessageData = msgData;
SessionCreate.Security security = new SessionCreate.Security();
SessionCreate.SecurityUsernameToken securityUserToken = new SessionCreate.SecurityUsernameToken();
securityUserToken.Username = userName;
securityUserToken.Password = password;
securityUserToken.Organization = org;
securityUserToken.Domain = domain; 
security.UsernameToken = securityUserToken; 
SessionCreate.SessionCreateRQ req = new SessionCreate.SessionCreateRQ();
SessionCreate.SessionCreateRQPOS pos = new SessionCreate.SessionCreateRQPOS();
SessionCreate.SessionCreateRQPOSSource source = new SessionCreate.SessionCreateRQPOSSource();
source.PseudoCityCode = PCC;
pos.Source = source;
req.POS = pos;
SessionCreate.SessionCreatePortTypeClient clientObj = new SessionCreate.SessionCreatePortTypeClient("SessionCreatePortType");
Task<SessionCreate.SessionCreateRQResponse> resp = clientObj.SessionCreateRQAsync(msgHeader, security, req);
resp.Wait();
inf.conversationID = msgHeader.ConversationId;
inf.sabreToken = security.BinarySecurityToken;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
return inf;
}

问题是URL只接受TLS 1.2,默认情况下可能不会启用。

在执行实例化的SessionCreate对象的类中,添加以下行:System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

这应该能解决问题

.NET 4.0或更高版本上的TLS 1.2
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

TLS 1.2在.NET 3.5上不受支持,因此我们使用它的数字表示
System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072;

最新更新