Create a new project (the web service).

  1. Create a new ASP.NET Empty Web Application project inside your solution.
  2. Right click on the newly created project and select Add > Web Service (ASMX) (or Add > New Item and find it).
  3. Create the methods you need inside of it. Don’t forget to add [WebMethod] above the method you want to use.
  4. When you are happy with it, right click the ASMX file and select View in Browser.
  5. In the browser, select and copy the location to the WS (in my case http://localhost:65057/WebService.asmx).

Add a reference to the old project.

  1. Right click on the old project and select Add > Service Reference.
  2. Paste the URL you copied to the Address field and click on Go, you should see the WS and the methods you exposed.
  3. Click on OK and you’re done.

Use the Web Service.

var ws = WebServiceSoapClient();
// WebService is the class name inside your WebService.asmx file.

Or, even better:

private WebServiceSoapClient _webServiceSoapClient;
WebServiceSoapClient WebService
        if (_webServiceSoapClient == null)
            _webServiceSoapClient = new WebServiceSoapClient();
        return _webServiceSoapClient;

var something = WebService.MethodName();

If you update your Web Service remember to right click on the Service Reference and select Update Service Reference (you might need to have the server running before by viewing the asmx file in your browser).

Leave a Reply

Your email address will not be published. Required fields are marked *