Jul
2
Written by:
Steve Gray
7/2/2009 2:55 PM
When I develop a VB application that calls a web service, I usually am developing the web service in the same solution. That's convenient, because you can step through and debug all the code.
But I'd also like to be able to deploy the web service and have my VB app call the live service. So...
Here's VB code that will call a web service with a dynamic URL. First, the app.config entry that makes it possible:
<appSettings>
<add key="webservicezzz" value="http://localhost/GPConnect.asmx" />
<add key="webservice" value="http://localhost:1906/eConnect/GPConnect.asmx" />
</appSettings>
What I do is manipulate the 'zzz's to call the dev or live service. (the one with the '1906' is the dev one... but you knew that)
Code to call the service in Visual Studio 2005:
Dim webService As localhost.GPConnect = New localhost.GPConnect
Dim strURL As String = System.Configuration.ConfigurationManager.AppSettings("webService")
webService.Url = strURL
webService.myMethod()
It's just a little different in 2008:
Dim strURL As String = System.Configuration.ConfigurationManager.AppSettings("webService")
Dim url As New System.ServiceModel.EndpointAddress(strURL)
Dim webService As New GPconnectLocal.GPConnectSoapClient
webService.Endpoint.Address = url
webService.Send("", "localhost", "")
As always, I welcome and comments or feedback.
As always, I welcome your comments!