问题
I am trying to create session using SessionCreateRQ soap service. which is first step of using sabre soap services where I have created object of HttpWebRequest with end point https://sws3-crt.cert.sabre.com and passing the request xml copied from sabre documentation to create a session
public HttpWebRequest CreateWebRequest()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://sws3-crt.cert.sabre.com");
webRequest.Headers.Add(@"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
public void Execute()
{
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""UTF-8""?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:eb=""http://www.ebxml.org/namespaces/messageHeader"" xmlns:xlink=""http://www.w3.org/1999/xlink"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema"">
<SOAP-ENV:Header>
<eb:MessageHeader SOAP-ENV:mustUnderstand=""1"" eb:version=""1.0"">
<eb:ConversationId/>
<eb:From>
<eb:PartyId type=""urn:x12.org:IO5:01"">999999</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId type=""urn:x12.org:IO5:01"">123123</eb:PartyId>
</eb:To>
<eb:CPAId>IPCC</eb:CPAId>
<eb:Service eb:type=""OTA"">SessionCreateRQ</eb:Service>
<eb:Action>SessionCreateRQ</eb:Action>
<eb:MessageData>
<eb:MessageId>1000</eb:MessageId>
<eb:Timestamp>2016-03-09T11:15:12Z</eb:Timestamp>
<eb:TimeToLive>2016-03-10T11:15:12Z</eb:TimeToLive>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse=""http://schemas.xmlsoap.org/ws/2002/12/secext"" xmlns:wsu=""http://schemas.xmlsoap.org/ws/2002/12/utility"">
<wsse:UsernameToken>
<wsse:Username>myUserName</wsse:Username>
<wsse:Password>myPasswordenter code here</wsse:Password>
<Organization>IPCC</Organization>
<Domain>DEFAULT</Domain>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<eb:Manifest SOAP-ENV:mustUnderstand=""1"" eb:version=""1.0"">
<eb:Reference xmlns:xlink=""http://www.w3.org/1999/xlink"" xlink:href=""cid:rootelement"" xlink:type=""simple""/>
</eb:Manifest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
but getting 500 error code on request.GetResponse(). Is there any problem with code or end point is wrong if its wrong please provide correct one.
回答1:
On the assumption your using visual studio use web reference rather than service reference. Service references seem create a bad proxy representation of the classes.
You can do this by right clicking on service reference.
Go t to advanced options in the bottom right and then clicking on add Web Reference. Then input the WSDL URL and consume the webservice from there.
Then something like this on the assumption you name your proxy class namespace SabreSesh should work.
Also might be worth noting that when generating proxy classes from sabre WSDL's sometimes you have to do a search and replace of the Reference.cs of and replace [][] with [] as it has a habit of translating the list and array schemas to double arrays when it shouldn't.
public SabreSessionInfo sabreCreateSession(string user, string pass, string pseudo, string iPseudo, bool doGetAirVendors)
{
SabreSessionInfo inf = new SabreSessionInfo();
try
{
userName = user;
password = pass;
iPCC = iPseudo;
PCC = pseudo;
string domain = "DEFAULT";
DateTime dt = DateTime.UtcNow;
string tstamp = dt.ToString("s") + "Z";
SabreSesh.MessageHeader msgHeader = new SabreSesh.MessageHeader();
msgHeader.ConversationId = "TestSession"; // Set the ConversationId
SabreSesh.From from = new SabreSesh.From();
SabreSesh.PartyId fromPartyId = new SabreSesh.PartyId();
SabreSesh.PartyId[] fromPartyIdArr = new SabreSesh.PartyId[1];
fromPartyId.Value = "WebServiceClient";
fromPartyIdArr[0] = fromPartyId;
from.PartyId = fromPartyIdArr;
msgHeader.From = from;
SabreSesh.To to = new SabreSesh.To();
SabreSesh.PartyId toPartyId = new SabreSesh.PartyId();
SabreSesh.PartyId[] toPartyIdArr = new SabreSesh.PartyId[1];
toPartyId.Value = "WebServiceSupplier";
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 = iPCC;
msgHeader.Action = "SessionCreateRQ";
SabreSesh.Service service = new SabreSesh.Service();
service.Value = "SessionCreate";
msgHeader.Service = service;
SabreSesh.MessageData msgData = new SabreSesh.MessageData();
msgData.MessageId = "mid:20001209-133003-2333@clientofsabre.com1";
msgData.Timestamp = tstamp;
msgHeader.MessageData = msgData;
SabreSesh.Security security = new SabreSesh.Security();
SabreSesh.SecurityUsernameToken securityUserToken = new SabreSesh.SecurityUsernameToken();
securityUserToken.Username = userName;
securityUserToken.Password = password;
securityUserToken.Organization = iPCC;
securityUserToken.Domain = domain;
security.UsernameToken = securityUserToken;
SabreSesh.SessionCreateRQ req = new SabreSesh.SessionCreateRQ();
SabreSesh.SessionCreateRQPOS pos = new SabreSesh.SessionCreateRQPOS();
SabreSesh.SessionCreateRQPOSSource source = new SabreSesh.SessionCreateRQPOSSource();
source.PseudoCityCode = iPCC;
pos.Source = source;
req.POS = pos;
SabreSesh.SessionCreateRQService serviceObj = new SabreSesh.SessionCreateRQService();
serviceObj.MessageHeaderValue = msgHeader;
serviceObj.SecurityValue = security;
lock (lockObject)
{
SabreSesh.SessionCreateRS resp = new SabreSesh.SessionCreateRS();
try
{
resp = serviceObj.SessionCreateRQ(req); // Send the request
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
inf.conversationID = msgHeader.ConversationId;
inf.sabreToken = security.BinarySecurityToken;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
return inf;
}
public class SabreSessionInfo
{
public string conversationID { get; set;}
public string sabreToken { get; set; }
public SabreSessionInfo()
{
conversationID = "";
sabreToken = "";
}
}
回答2:
There's an existing .NET sample in Dev studio, using proxy code/classes:
https://developer.sabre.com/docs/read/soap_basics/getting_started
Hope that helps.
来源:https://stackoverflow.com/questions/35897341/consuming-sabre-soap-services-using-net