Accessing a web service from a vb.net windows form application

I have a web service that I have added as a web refernce in my vb.net application.  The web service was created vs2005.  I added a web reference in my vb.net application and it shows up as:

Web Reference     
       localhost

 

The actual name of my webservice is http://localhost:2758/WebSite4/Service.asmx

Now for my question, how do I declare an instance of my new web service in my windows form application

Private MyWebService as localhost.service=new localhost.service  does not appear to work.  So I guess I don't understand what a Web Reference of local host means and how to create an instance of my web service.

 

Thanks,

Fred Herring




Answer this question

Accessing a web service from a vb.net windows form application

  • mpenalor

    Thankyou very much Vikram, clarity at last.  I could not function without the msdn forums.

     

    Thanks again,

    Fred Herring



  • RJDBA

    Hi,

    You are correct in setting the IP Address.The issue here is that your web site is not using IIS currently. In VS2005, you can build WebSites without using IIS for development purposes. However when you to expose these to the external world u need to make use of IIS.

    So, open your website in VS2005, goto Build Menu and choose the Publish option. Click on the "..." button in the Target Location and select Local IIS and specify the path as : http://localhost/WebSite4. Now people will be able to access the service from other machines.

    Regards,

    Vikram



  • tschissler

    Thanks for the link.  I set the urlstatus property from static to dynamic.  Now I get an entry called app.config

     

    < xml version="1.0" encoding="utf-8" >

    <configuration>

    <appSettings><add key="OfficeManager.localhost.Service" value="http://localhost:2758/WebSite4/service.asmx"/></appSettings></configuration>

     

    What confuses me is nowhere is my ip address exposed.  Would not a client computer on the net need to know the ip address of the server exposing a named web service. 

    Whenever I try to substitute an ip address for localhost such as

    http://24.22.222.xx/WebSite4/service.asmx, I get

    Server cannot access application directory 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\WebSite4\'. The directory does not exist or is not accessible because of security settings.

     

    So my question deals with how to tell a non local machine how to reach my web service.

     

    Thanks,

    Fred Herring



  • Mark DAlton

    Hi,

    The webservice instance exposes a property called Url which you can set at runtime or save in the web.config and retrieve at runtime and set the property just before u make the call to the web method.

    Check the following URL for more info: http://aspalliance.com/283

    Regards,

    Vikram



  • helmut.b

    Hi Fred,

    The default namespace also gets prefixed before localhost. So if your default namespace is WindowsApplication1, then it would be :

    Dim objService As New WindowsApplication1.localhost.CurrencyExchangeService()

    Regards,

    Vikram

     



  • BenChen

    Thanks for the rapid reply.   I am confused about one thing.  When I create a web reference to:  http://localhost:2558:Website4/Service.asmx, don't I eventually need to replace localhost with my ip address.  When I try to do that, I can't rearch my web service anymore.  Can you show me the format of a web reference with an ip address.

     

    Thanks,

    Fred Herring



  • Accessing a web service from a vb.net windows form application