2017-05-15 22 views
0

這是相當普遍的,但我有一段時間搞清楚如何使用一些更復雜的Saber API。我已經在C#中使用WSDL爲基本API(CreateSession,CloseSession)構建了可用的.NET代理類,但是對於更復雜的API,我很難分析出複雜的XML模式來找出哪些方法在我的程序中打電話。Saber Web服務.NET API不是MVC的示例?

是否還有其他.NET資源/示例沒有包含在MVC中,如code example that Sabre posted on GitHub

我想弄清楚如何使用API​​如OTA_AirPriceLLSRQ和TravelItineraryReadRQ。

在此先感謝您的幫助!

+0

沒有其他來源,至少由Saber提供,我知道。儘管如此,如果您所指的MVC是正確構建的,那麼您應該只關注模型,因爲控制器中應該幾乎沒有代碼,而視圖應該只是一個視圖。 有什麼服務,你有特殊的麻煩? – Wisdoom

+0

謝謝!我試着挖掘所提供的模型,但我很迷茫;他們使用多個接口和服務工廠構建代碼的方式超出了我的想象。我正在尋找一種非常簡單的基於對象的方法來允許我實例化一個API調用,然後使用它的響應。我確定他們構建MVC應用程序的方式效率更高,但對於我的noob頭腦來說太複雜了。 我覺得如果我能找到一些簡單方法的例子,我可以開始理解代理類足以實現Saber公開的大多數API的自己的類。 – drtrobridge

+0

我完全理解你,我面臨同樣的情況。你想打什麼服務?我可能會有,我可以在這裏複製我的課 – Wisdoom

回答

0

我的建議是你應該添加基於Saber模型構建的單獨模型,並且將整個結構展平。

例如,TravelItineraryReadRS是一個相當複雜的文件。在程序中使用它的屬性是一個真正的「痛苦」,因爲每次你需要記住導致特定信息的整個路徑(比如,「NameNumber 01.01的PersonName的乘客類型是什麼?」)。

我建議你有專門的模型(我們將其命名爲Reservation),其中包含您的應用程序中稍後需要的所有信息,從TravelItineraryReadRs中提取。 爲了實現這一點,你需要一個專用的轉換器,它將使TravelItineraryReadRs模型轉換爲Reservation模型。現在,在Reservation模型中,您可以列出Passenger模型,其中包含所有重要信息(NameNumber,PassengerType,SSR代碼等)。

這提高了可讀性,並且作爲獎勵將應用程序與Saber分離(想象一下,有人問我們「我們可以從Saber轉換到Amadeus嗎?」 - 如果使用專用模型,答案是「是」。沒有,那麼答案是「可能是的,但它將需要6-9個月)。

+0

感謝您的建議 - 我實際上已經創建了一組類似的對象模型,無論Saber通過解析出本機Saber通過簡單的'SabreCommandLLSRQ' API進行響應。 我現在最大的問題是理解C#中創建的代理類的複雜性,並瞭解如何使用這些類正確格式化請求並處理響應。由於我想消費的大多數API都非常複雜,我似乎無法讓它們中的任何一個都可以工作(除了像CreateSession這樣簡單的工作) – drtrobridge

1

正如我在評論中提到的,你不應該專注於實際的MVC包裝,因爲你將主要把在模型中的東西,或者實際上你會把它放在其他地方,並在模型中消耗它。秒。使用這種方法需要創建一個實例,並在調用Execute方法之後將響應存儲在實例中。

我希望它有幫助。

using BargainFinderMaxRQv310Srvc; 
using System; 
using System.IO; 

namespace ServicesMethods 
{ 
    public class BFM_v310 
    { 
     private BargainFinderMaxService service; 
     private OTA_AirLowFareSearchRQ request; 
     public OTA_AirLowFareSearchRS response; 

     public BFM_v310(string token, string pcc, string convId, string endpoint) 
     { 
      //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 = "BargainFinderMaxRQ"; 
      mHeader.Service = new Service() 
      { 
       Value = mHeader.Action 
      }; 
      mHeader.ConversationId = convId; 
      mHeader.CPAId = pcc; 
      mHeader.From = from; 
      mHeader.To = to; 
      mHeader.MessageData = new MessageData() 
      { 
       Timestamp = DateTime.UtcNow.ToString() 
      }; 

      //Security 
      Security security = new Security(); 
      security.BinarySecurityToken = token; 

      //Service 
      service = new BargainFinderMaxService(); 
      service.MessageHeaderValue = mHeader; 
      service.SecurityValue = security; 
      service.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap11; 
      service.Url = endpoint; 

      createRequest(pcc); 
     } 

     private void createRequest(string pcc) 
     { 
      request = new BargainFinderMaxRQv310Srvc.OTA_AirLowFareSearchRQ(); 
      request.AvailableFlightsOnly = true; 
      request.Version = "3.1.0"; 

      request.POS = new SourceType[1]; 
      SourceType source = new SourceType(); 

      source.PseudoCityCode = pcc; 
      source.RequestorID = new UniqueID_Type(); 
      source.RequestorID.ID = "1"; 
      source.RequestorID.Type = "1"; 
      source.RequestorID.CompanyName = new CompanyNameType(); 
      source.RequestorID.CompanyName.Code = "TN"; 
      source.RequestorID.CompanyName.CodeContext = "Context"; 
      request.POS[0] = source; 

      OTA_AirLowFareSearchRQOriginDestinationInformation originDestination = new OTA_AirLowFareSearchRQOriginDestinationInformation(); 
      originDestination.OriginLocation = new OriginDestinationInformationTypeOriginLocation(); 
      originDestination.OriginLocation.LocationCode = "BCN"; 
      originDestination.DestinationLocation = new OriginDestinationInformationTypeDestinationLocation(); 
      originDestination.DestinationLocation.LocationCode = "MAD"; 
      originDestination.ItemElementName = ItemChoiceType.DepartureDateTime; 
      originDestination.Item = "2017-09-10T12:00:00"; 
      originDestination.RPH = "1"; 
      request.OriginDestinationInformation = new OTA_AirLowFareSearchRQOriginDestinationInformation[1] { originDestination }; 

      request.TravelerInfoSummary = new TravelerInfoSummaryType() 
      { 
       AirTravelerAvail = new TravelerInformationType[1] 
      }; 
      request.TravelerInfoSummary.AirTravelerAvail[0] = new TravelerInformationType() 
      { 
       PassengerTypeQuantity = new PassengerTypeQuantityType[1] 
      }; 
      PassengerTypeQuantityType passenger = new PassengerTypeQuantityType() 
      { 
       Quantity = "1", 
       Code = "ADT" 
      }; 
      request.TravelerInfoSummary.AirTravelerAvail[0].PassengerTypeQuantity[0] = passenger; 

      request.TravelerInfoSummary.PriceRequestInformation = new PriceRequestInformationType(); 
      request.TravelerInfoSummary.PriceRequestInformation.CurrencyCode = "USD"; 
      //PriceRequestInformationTypeNegotiatedFareCode nego = new PriceRequestInformationTypeNegotiatedFareCode(); 
      //nego.Code = "ABC"; 
      //request.TravelerInfoSummary.PriceRequestInformation.Items = new object[1] { nego }; 
      request.TPA_Extensions = new OTA_AirLowFareSearchRQTPA_Extensions(); 
      request.TPA_Extensions.IntelliSellTransaction = new TransactionType(); 
      request.TPA_Extensions.IntelliSellTransaction.RequestType = new TransactionTypeRequestType(); 
      request.TPA_Extensions.IntelliSellTransaction.RequestType.Name = "50ITIN"; 


     } 

     public bool Execute() 
     { 
      response = service.BargainFinderMaxRQ(request); 

      return response.PricedItinCount > 0; 
     } 
    } 

} 
+0

太棒了!這非常有幫助;感謝您抽出寶貴的時間。 如果你今年要參加TTX,請告訴我 - 我會給你買一杯雞尾酒或六杯。 – drtrobridge

+0

去年我去過那裏,但遺憾的是今年我不會去那裏,但是謝謝你的感悟! :) – Wisdoom