2011-09-20 146 views
0

我在我的項目的一個Web服務的參考,但它有兩個網址一個是生活和第二個考驗是,如何動態地在vb.net這些URL之間切換如何更改Web服務URL動態

http://api.test/test/SOAP.wsdl
http://api.live/live/SOAP.wsdl

 'LOGPOINT: 
     Call mobjLogWrite.prWriteLogEntry(clsLogWriter.enuLogEntryType.INFORMATION, ASSEMBLY_ID, "Start fnHOTELSPROSearchExecute()", "fnHOTELSPROSearchExecute") 

     Dim objsoap As New b2bHotelSOAPService() 
     Dim getres As New getAvailableHotelResponse() 
     QLSearchXML = xmlData 
     objsoap.Timeout = 20000 
     objsoap.Url = "http://api.live/live/SOAP.wsdl" 
     'objsoap.Timeout = TIMEOUT 
     getres = objsoap.getAvailableHotel(HOTELSPRO_APIKEY.Trim(), strDestinationId, dtmCheckIn, dtmCheckOut, strCurrencyCode, "UK", True, fngetpax(xmlData), getfilter()) 
     Call mobjLogWrite.prWriteLogEntry(clsLogWriter.enuLogEntryType.INFORMATION, ASSEMBLY_ID, "Start DeSerializing the XML Output", "fnHOTELSPROSearchExecute") 
     lHOTELSPROReturn = fnCustomSerializeObject(GetType(getAvailableHotelResponse), getres) 
     Call mobjLogWrite.prWriteLogEntry(clsLogWriter.enuLogEntryType.INFORMATION, ASSEMBLY_ID, "End DeSerializing the XML Output", "fnHOTELSPROSearchExecute") 
     lTempDOM.LoadXml(lHOTELSPROReturn) 
     Return lTempDOM 

    Catch ex As Exception 
     Call mobjLogWrite.prWriteLogEntry(clsLogWriter.enuLogEntryType.ERROR, ASSEMBLY_ID, "Catch Block Error:" + ex.ToString(), "fnCreateHOTELSPROSearchRequest") 

    Finally 
     'LOGPOINT: 
     Call mobjLogWrite.prWriteLogEntry(clsLogWriter.enuLogEntryType.INFORMATION, ASSEMBLY_ID, "Response From HotelsPro--->" & lHOTELSPROReturn, "fnHOTELSPROSearchExecute") 
     Call mobjLogWrite.prWriteLogEntry(clsLogWriter.enuLogEntryType.INFORMATION, ASSEMBLY_ID, "END Finally Block fnHOTELSPROSearchExecute()", "fnHOTELSPROSearchExecute") 
    End Try 

錯誤響應返回

「我已經在我的項目一個web服務的參考,但它有兩個網址一個是生活和第二個是TES t,如何在vb.net中動態地切換這些網址「

+0

objsoap.Url = someurl是正確的,你確定這兩個web服務是相同的嗎?什麼是錯誤?你可以在這裏發佈嗎? – Stefan

+0

@Duke我可以知道你在fngetpax(xmlData),getfilter()這些函數中發送了什麼。因爲我也有與hotelsPro.com工作,並沒有在c#中找到任何例子# – rahularyansharma

回答

1

動態地基於什麼,到底是什麼?

假設你根據在應用程序正在運行,即測試或現場,怎麼樣的意思是:

編輯:剛剛看到它的意思是在VB.Net

Dim MyService as String 
If HttpContext.Current.Server.MachineName.ToString() = "LIVESERVER" Then 
    MyService = "http://api.live/live/SOAP.wsdl" 
Else 
    MyService = "http://api.live/test/SOAP.wsdl" 
End If 

而且改變

objsoap.Url = "http://api.live/live/SOAP.wsdl" 

objsoap.Url = MyService 
+0

你有任何關於HotelsPro.com api的想法,因爲我想知道什麼是通過PAX和篩選器 – rahularyansharma

+0

我檢查那裏的文檔,但它令我困惑因爲我不知道PHP,並且PHP中有相同的像$ rooms = array(); //第一個房間 $ rooms [] = array(array(「paxType」=>「Adult」)); (array)(「paxType」=>「Adult」),數組(「paxType」=>「Child」,「年齡「=> 8)); – rahularyansharma

0

如果您的Webservice設置爲動態,則該URL存儲在app.config設置中。爲了使它在運行時更易於更改(app.config只讀,除非以管理員權限運行),請轉到項目設置並將Web服務設置從應用程序範圍更改爲用戶範圍。

現在你可以使用my.settings.yourwebserviceurl在代碼隨時更改Web服務URL ... =「newwebserviceurl」

調用WebService的下一次,這將是新的位置。但是,您需要確保這兩個Web服務調用都包含一個不變的或至少兼容的Web服務。