【发布时间】:2018-07-17 22:54:37
【问题描述】:
我正在尝试使用 C# 调用 HotelPropertyDescriptionLLSRQ Sabre Web 服务。我已经让其他 API 可以使用类似的代码,但我仍然收到相同的客户端验证失败错误,即使在检索到有效的安全令牌之后也是如此。
我想我在代理模型中遗漏了一些小部分,如下所示。
搜索条件对象:
HotelSearchCriteria searchCriteria = new HotelSearchCriteria
{
hotelCode = "1191",
inDate = "8-22",
outDate = "8-25"
};
然后是代理类:
public class HotelPropertyDescriptionReq
{
private HotelPropertyDescriptionService service;
private HotelPropertyDescriptionRQ req;
public HotelPropertyDescriptionRS response;
public string xmlResponse;
public bool searchPerformed = false;
public HotelPropertyDescriptionReq()
{
//parameterless constructor for serialization
}
public HotelPropertyDescriptionReq(SessionToken token, HotelSearchCriteria searchCriteria)
{
//argument validation - must have a location of some sort and some dates for search to work. Throw exception here if none found
if (searchCriteria.hotelCode == null && searchCriteria.cityCode == null)
{
//no search can take place if this is null...send back an empty response with searchPerformed == fals
throw new ArgumentException("Cannot search hotel availability without hotelCode or cityCode");
}
else if (searchCriteria.inDate == null || searchCriteria.outDate == null)
{
throw new ArgumentException("Cannot serach hotel availability without inDate and outDate");
}
//MessageHeader
MessageHeader mHeader = new MessageHeader();
PartyId[] pId = { new PartyId() };
pId[0].Value = "SWS";
From from = new From();
from.PartyId = pId;
To to = new To();
to.PartyId = pId;
mHeader.Action = "HotelPropertyDescriptionLLSRQ";
mHeader.version = "2.3.0";
mHeader.Service = new Service()
{
Value = mHeader.Action
};
mHeader.ConversationId = token.conversationID;
mHeader.CPAId = token.ipcc;
mHeader.From = from;
mHeader.To = to;
mHeader.MessageData = new MessageData()
{
Timestamp = DateTime.UtcNow.ToString(),
};
//Security
//Security sec = new Security();
Security1 sec = new Security1();
sec.BinarySecurityToken = token.securityToken;
//Service
service = new HotelPropertyDescriptionService();
service.MessageHeaderValue = mHeader;
//service.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap11;
service.Security = sec;
//request
req = new HotelPropertyDescriptionRQ();
req.AvailRequestSegment = new HotelPropertyDescriptionRQAvailRequestSegment();
req.AvailRequestSegment.GuestCounts = new HotelPropertyDescriptionRQAvailRequestSegmentGuestCounts();
req.AvailRequestSegment.GuestCounts.Count = "1";
req.AvailRequestSegment.HotelSearchCriteria = new HotelPropertyDescriptionRQAvailRequestSegmentHotelSearchCriteria();
req.AvailRequestSegment.HotelSearchCriteria.Criterion = new HotelPropertyDescriptionRQAvailRequestSegmentHotelSearchCriteriaCriterion();
req.AvailRequestSegment.HotelSearchCriteria.Criterion.HotelRef = new HotelPropertyDescriptionRQAvailRequestSegmentHotelSearchCriteriaCriterionHotelRef();
req.AvailRequestSegment.HotelSearchCriteria.Criterion.HotelRef.HotelCode = searchCriteria.hotelCode;
req.AvailRequestSegment.TimeSpan = new HotelPropertyDescriptionRQAvailRequestSegmentTimeSpan();
req.AvailRequestSegment.TimeSpan.Start = searchCriteria.inDate;
req.AvailRequestSegment.TimeSpan.End = searchCriteria.outDate;
string requestXML = Serializer.toXML(req);
string headerXML = Serializer.toXML(mHeader);
//send the request
try
{
response = service.HotelPropertyDescriptionRQ(req);
searchPerformed = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
}
【问题讨论】:
-
能否请您发布生成的肥皂请求?从那里调试更有意义。
-
我使用 Pastebin 将 XML 放到网上,因为它不适合 cmets - 如果这不是提供它的最有用的方式,请告诉我。感谢您的输入! pastebin.com/9TPZXaWg
-
我不知道你的请求中的“-”是从哪里来的,但他们一定要去。整体看起来有点畸形。将添加一个工作请求。
标签: c# .net web-services soap-client sabre