Saturday, January 1, 2011

Writing a C# client to an Axis2 service

Before moving into today's post content I would like to wish all the readers a happy new year 2011!

I am writing this post assuming you already have read my previous post subjected "Getting started with Apache Axis2". In there the client code has written in java, assume a situation where you need to write a client with C#, it is even simpler than writing a client in java.All you have to do is create a new project using microsoft visual studio and add the wsdl of your service(for the given example it is http://localhost:8080/axis2/services/mywebservice?wsdl) as service references and give a desired name for it(in following sample client code it is webserviceref), write the client code and run it



Client.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using webservice.clients.webserviceref;//name space of the service reference

namespace webservice.clients
{
    class Myclient
    {
        static void Main(string[] args)
        {

            webserviceref.mywebservicePortTypeClient cli = new mywebservicePortTypeClient("mywebserviceHttpSoap12Endpoint");
            Console.WriteLine(cli.sayHello("Hello"));
            Console.ReadLine();

        }
    }
}


Note that you have to start axis2 server before running the program.

4 comments :