bbesase
bbesase

Reputation: 861

How to reference my added web service

This is my first time dealing with Web Services. I have successfully Added a Web Service to one that I have created in VS 2010. What I'm trying to do is access the functions of the added web service in this .asmx file This is what I see now along with all the auto added code.

Service1.asmx.vb

Public Class Service1
Inherits System.Web.Services.WebService


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

The added web service that I have added is called blahService. So I'm just curious as how do I access the functions that are in the added web service? Do I have to do something like this...?

Dim foo as new blahService()

Then when I go to access a function just do

foo.function()

Upvotes: 0

Views: 27

Answers (1)

Faisal
Faisal

Reputation: 364

1) From within your Solution Explorer of your project, right-click on “Service References”, then click on “Add Service Reference”

2) The dialog box which appears allows you to put in the URL of your web service. Enter it, then press the “Go” Button”

3) You can see that the name of the web service appears in the Services pane. Give your webservice a namespace (anything you like) that will be used to refer to it from within your project. Press the OK button. That namespace will now appear in the list of Service References

A web service is considered to have anonymous authentication if no specific permission is required to access it. The server is allowed to fulfill every request without regard to the entity who is requesting the information. This is the case for many web services on the internet.

For reference, this is the source code for the method which I will be calling from my application:

 [WebMethod]
  public List<string> GetStrings(int StartNumber, int EndNumber)
   {
        List<string> MyList = new List<string>();
        for (int i = StartNumber; i <= EndNumber; i++)
         {
            MyList.Add("AuthASMXService String #" + i.ToString());
         }
         return MyList;
  }

and here’s the code that will call the method in the web service instantiated above:

  private void ASMXWebServiceInvoke_Click_1(object sender, RoutedEventArgs e)
 {
     ASMXWebServiceReference.WebService1SoapClient MyASMXWebServiceClient 
      = new ASMXWebServiceReference.WebService1SoapClient();
     ASMXWebServiceReference.GetStringsResponse MyStringsResponse = 
      MyASMXWebServiceClient.GetStrings(10, 20);
     ASMXWebServiceReference.ArrayOfString MyStrings = 
      MyStringsResponse.Body.GetStringsResult;
     ASMXGridView.ItemsSource = MyStrings;
 }

How do I connect to an ASMX web service?

Upvotes: 1

Related Questions