Visual Studio-Sabre GetReservationRS在Intellisense中未显示旅行项目

时间:2018-07-20 20:51:06

标签: c# visual-studio wsdl soap-client sabre

我正在尝试实现新的GetReservationRQ / RS API,因为旧的TravelItineraryReadRQ显然将于2018年12月停用。

我能够进行呼叫并获得响应,并且所有有效的旅行数据都存在于XML有效负载中,但是我无法获得Intellisense来在代理类的Item字段中显示项目。我可能解释不正确,所以下面有一些屏幕截图。

我尝试挖掘由WSDL创建的reference.cs文件,但确实看到在GetReservationRQ和TravelItinerarReadRQ之间创建对象模型的方式有所不同,但是我对此无所适从它。

处于调试模式的人口对象,显示所有有效的保留项目:

enter image description here

没有任何其他可见成员的智能显示项目字段:

enter image description here

编辑7/26/18

由于下面的卡洛斯(Carlos)的回答,我通过实施他的更改使这项工作得以实现。对于子孙后代,这是我的工作代码:

public class GetReservationReq
{

    private GetReservationService service;
    public GetReservationRS response;
    public string xmlResponse;

    public GetReservationReq()
    {
        //parameterless constructor for serializiation
    }

    public GetReservationReq(SessionToken token, string locator)
    {
        //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 = "getReservationRQ";
        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 GetReservationService();
        service.MessageHeaderValue = mHeader;
        service.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap11;
        service.SecurityValue = sec;

        //create the request
        GetReservationRQ req = new GetReservationRQ();
        req.Version = "1.18.0";
        req.RequestType = "Stateful"; //This indicates that we are looking to pull up an existing PNR
        req.Locator = locator;
        req.ReturnOptions = new ReturnOptions();
        req.ReturnOptions.ViewName = "Full";
        req.ReturnOptions.ResponseFormat = "STL";


        try
        {
            //execute the response
            response = service.GetReservationOperation(req);
            //cast response items to usable Object 
            ReservationPNRB content = (ReservationPNRB)response.Item;
            //testing - iterate through reservation elements and do stuff
            foreach (var segment in content.OpenReservationElements.OpenReservationElement)
            {
                Console.WriteLine(segment.id + " - " + segment.type);
            }
            Console.Read();

            //serialize the response for logging if necessary
            xmlResponse = Serializer.toXML(response);


            //serialize response for logging if necessary
            using (StreamWriter myWriter = new StreamWriter(@"C:\SABRE_DATA\TMP\xmlItin.txt", true))
            {
                XmlSerializer mySerializer = new XmlSerializer(typeof(GetReservationRS));
                mySerializer.Serialize(myWriter, response);
                StringWriter myStringWriter = new StringWriter();
                mySerializer.Serialize(myStringWriter, response);
                xmlResponse = myStringWriter.ToString();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            throw;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

如您在上一个打印屏幕中所见,Item属性的类型为Object。这意味着您需要将其转换为期望的特定类型。

要找到可以在该属性中返回的有效类型,您需要转到reference.cs,在该位置的顶部您将看到该API可以返回的对象的有效类型(作为属性)在这个属性中。