Duke
Duke

Reputation: 1

How to change web service url dynamically

I have one web service reference in my project but it has two url one is live and second one is test,how to switch between these url dynamically in vb.net

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

the error response is returned

"I have one web service reference in my project but it has two url one is live and second one is test,how to switch between these url dynamically in vb.net"

Upvotes: 0

Views: 6969

Answers (2)

Craig Stewart
Craig Stewart

Reputation: 41

If your Webservice is set to Dynamic, the URL is store in the app.config settings. To make this easier to change at run time (the app.config is readonly unless run with admin privileges), go to the project Settings and change the webservice setting from application scope to user scope.

Now you can change the webservice URL at any time in code using the my.settings.yourwebserviceurl... = "newwebserviceurl"

Next time you call the webservice, it will be from the new location. However, you will need to ensure both webservice call contain an indentical, or at least compatible webservice.

Upvotes: 0

Widor
Widor

Reputation: 13275

Dynamically based on what, exactly?

Assuming you mean based on where the app is running, i.e. Test or Live, how about:

EDIT : Just saw it was meant to be in 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

And change

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

to

objsoap.Url = MyService

Upvotes: 1

Related Questions