Wednesday, February 20, 2008

Creating a .net webservice client

I was working with getting some .net client and services with WSF/PHP. So thought of providing some usefull information to anyone interested. I will go through the process of getting WSF/PHP services and clients working with .net clients and services in the next few days. I start with writing on how to create a C# web service client, provided that you have a valid wsdl file or and endpoint which provides a valid wsdl for ?wsdl option.

In visual Studio, go to new project->C#->Windows->Console application, and give your prefered name for a client. I will use name DemoClient for my client.

Step 2.
Now you should be able to see the project from solutions explorer. Right click on the project and select the option, add Web Reference.

Then In AddWebReference dialog box, provide the url to your wsdl and click on the go button. Next provide a name for the web reference. Now you should have a web reference generated and added to your project. I used the WSDL Mode sample (wsdl_11_service.php) service that comes with WSF/PHP for generating this web reference.

The name you give for your web reference will become a namespace in your project. I gave the name PurchaseOrder for the Web Reference. So the proxy code for this web service invocation will be generated with the namespace (Purchase Order).
Now in the my client code, I import this namespace.
using DemoClient.PurchaseOrder;
The service described in WSDL will be available as C# class to the client code. The operations defined for each service in the WSDL will become methods of the class. So invoking the web service operation is as simple as creating an instance of the required service class and calling the needed operation on it.
ShippingTradeService stp = new ShippingTradeService();
int type = stp.GetType();


  1. janis - the dutchmanMarch 13, 2011 at 9:21 AM

    this php webservice with wsdl and the client soap in sharp is great :D

    here is my php webserver with wsdl so you can test it all :)

    using Soapclient.WebReference;

    namespace Soapclient
    class Program
    static void Main(string[] args)
    SoapService c = new SoapService();

    float b = c.toFahrenheit(22);



    addFunction( 'toFahrenheit' );

    i.nput = remove the dot '.'

    Reken graden om naar fahrenheit

  2. janis - the dutchmanMarch 13, 2011 at 9:24 AM

    mmm... bad editor :S:S

    here the files..