Paymon Wang-Lotfi
Paymon Wang-Lotfi

Reputation: 555

How to call a simple Web Service

I have a C# file named Service1.cs containing the following:

public class Service1 : System.Web.Services.WebService
{ 
    [System.Web.Services.WebMethod]
    public static String testMethod()
    {
       return "Hello";
    }
}

I put this snippet of code in my helloworld.html file:

<WebService Language="c#" Codebehind="Service1.cs"
    Class="Service1.Service1">

My directory is up at http://localhost:8000/, with a link to helloworld.html and a link to download Service1.cs

to what url must I go to to access the string returned by my testMethod()?

I've tried http://localhost:8000/helloworld/testmethod, http://localhost:8000/helloworld/Service1/testmethod, but I can't figure out how to get to the string value returned from the web service.

Thanks in advance.

Upvotes: 0

Views: 13561

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222722

You can right click the Project -> References and click Add Service references and paste the url,

enter image description here

Create a client like this and call method:

myService.Service1Client client = new myService.Service1Client();
var result = client.testMethod();

Upvotes: 6

Related Questions