How to discover web services dynamically?

ProgMan

Well-known member
Joined
Nov 25, 2006
Messages
55
Location
UK
Programming Experience
3-5
Hi everybody :)

I have just started looking into web services using Visual Studio 2005. I can create and consume a simple web service using VB.Net. Now I'm trying to create webservices like for an online store where it has branches in different locations and each location has their own services. So, for example, if I want to know the stock level of a particular item, it should check webservice1 (location1), then webservice2 (location2) etc.

So far I've found that it has something to do with the .vsdisco but I'm not sure how exactly to do the task.

Can anyone help me out on this ? I tried to search on the net without much success :(

N.B. Please note that I'm pretty new in the arena so would be grateful if someone provides with some example codes I can play with.

Thank you.
 
You want to point an existing design-time generated proxy to a different URL? Just create a new instance of the web service proxy class and change the .Url property. You are familiar with the 'localhost' proxy namespace and understand this example:
VB.NET:
Dim ws As New localhost.Webservice
ws.Url = "http://newaddress.asmx"
Dim return As localhost.CustomType = ws.getReturn()
Maybe you're interested in this article that explains some basic terms: Introduction to .NET Web Services
 
Thanks JohnH for your reply.

Erm...as I said I'm very new to this...:eek:

I used Visual Studio 2005 to create a .net web service and it did it straight away. So, I didn't understand what was happening behind the scene. I've read a couple of articals where it explains about proxy stubs but I can't relate (see) those when using VB 2005. For example I can only see the following codes that's automaticlly generated-

VB.NET:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
     Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

End Class
So, when you say to create a new instance of localhost.webservice, I'm not sure where to put it! I tried to put the the lines you provided in the above code section but I get error as localhost.webserice is not recognised :(


N.B My apology again as I feel that perhaps I'm asking a to dumb question :eek:
 
I was talking about the consumer, this is where you want to point to different webservice address isn't it? The localhost.Webservice class the consumer creates an instance of is called the proxy, this class is generated at design time when you add web reference, it is generated from the service description (wsdl).
 
Thanks JohnH, I understand now what you mean. But I guess (I might be wrong!) what you've suggested won't be a dynamic discovery. What I'm trying to do is that my application should dynamically discover the webservices (for example, I shouldn't create a static proxy service within the application instead the discovery should be done via code).

This is where I guess .vsdisco comes into action but again as a complete newbie on this, I might've made no sense at all! :eek:
 
You mean to list the methods of any unknown webservice in a listbox for a human to choose to invoke? That rarely makes sense as webservices aren't designed for direct human interaction, they are designed as helper methods for other presentation layers like webpages and desktop applications, or for other code layers to use to get data. In many cases also a human is not able to provide the input parameters as they can be complex types defined by the service, and not able to read the result for the same reason.

Even though its possible to dynamically bind to a unknown webservice through code and check and invoke its methods by reflection that really don't make any sense.

.vsdisco is just a pointer to where the current sites webservices is, pointing to the wsdl that describes these webservices.
 
Thanks again JohnH for your continuous support. I think I understand now. However, I get confused when I read the following articles. These documents talk about dynamic discoveries and .vsdisco files. But so far I understand now is that, those are talking about something like when more than one web services are located in one place (server) and these actually does not apply to my scenario. Please let me know if I'm correct.

http://www.15seconds.com/Issue/010430.htm

http://www.codeproject.com/dotnet/intro2websvc.asp
 
The conclusion is correct. You can use the discovery address also when adding the web reference in Visual Studio, because it points to the description document it needs to generate the proxy class, which is needed to make the calls to the webservice.
 
:s

I am lost again !!! :(

Someone has told me today that the way to discover webservices dynamically has to do something with UDDI and something called 'reflections' (but I didn't have a clue what he was talking about!)....:confused:

I'm feeling very low at the moment... :( :( :(
 
I would say what you are asking for is a very bad idea, but you can pursue your "everything, everything" goal if you wish, although this is not what webservices are about. "Reflection" is the way to go to discover and use any unknown type definition.
 
Thanks JohnH. I am glad to see that you are still around to help :)

Well, first of all an apology :eek: . I guess its my imaginary scenario I described earlier is causing all the confusions. When I created the scenario in my previous posts, I knew very little about web services (I still don't know much but I'm learning...:) )


But, basically I am interested in learning about discovering 'Unknown webservices and their operations'. This is acually what I meant when I said 'dynamic discovery'. But the scenario I created was not correct which made everyone confused...:eek:

I hope now you have a clear idea on what I'm trying to do . So, I would be obliged if you kindly guide me step by step.

Thanks again JohnH for your continuous support and feedbacks. :)
 
Back
Top