How can I minimize the lines of code that must change when I need to change the URL for a Web Service object? Use a Function call as the object to qualify the Web Service Method call rather than creating an object representing the Web Service.
I recently put a relatively complex application into production. The client application uses a Web Service to call Remote Objects to get data from the database. This application is a DashBoard Monitoring application that management uses to monitor operations in the production facility. Since there are multiple users of this client application, I developed a Cache Object that periodically updates itself so that multiple users don't cause extra database hits.
The client application is using threading to keep the UI active while retrieving data from the remote object, which can take several seconds to retrieve all of the data for the various grids, graphs, and other stats shown on the main form. There are dozens of places throughout the application where the Web Service is called. I was creating an object of the Web Service in numerous places, in the form of the code shown below:
| Private Function GetData() As DataTable Dim ws As New remotepAppServ.MyWebService Dim ds As DataSet = ws.GetJobsByHour( _ Me.dtpStartDate.Value, DateAdd(DateInterval.Day, 1, _ Me.dtpEndDate.Value)) Dim dt As DataTable = ds.Tables(0) Return dt End Function |
| Private Function GetData() As DataTable Dim ws As New MyAppServ.MyWebService Dim ds As DataSet = ws.GetJobsByHour( _ Me.dtpStartDate.Value, DateAdd(DateInterval.Day, 1, _ Me.dtpEndDate.Value)) Dim dt As DataTable = ds.Tables(0) Return dt End Function |
| Public Function GetWebServiceObject() As infoproappserv.InfoProWebService ' Return New localhost2.MyWebService Return New RemoteAppServ.MyWebService End Function |
| Private Function GetTranscribedData() As DataTable Dim ds As DataSet = _GetWebServiceObject(). _ GetJobsByHour(Me.dtpStartDate.Value, _ DateAdd(DateInterval.Day, 1, Me.dtpEndDate.Value)) Dim dt As DataTable = ds.Tables(0) Return dt End Function |