Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone furnish a simple Hello World type example where a C# client consumes a Soap::Lite web service?

The minimum requirement for my purposes is that the method called return at least some result (i.e. the string 'Hello World').

Replies are listed 'Best First'.
Re: C# client for Soap::Lite
by fauria (Deacon) on Jun 06, 2005 at 18:50 UTC
    SOAP is platform and language independent, it means that you can have a server written in any language (Perl in this case) that talks to any client written in any other language by using XML messages.

    So you only need to write a SOAP client in C#, make it point to your Perl server, call any method exported and it will work.

    You have several samples in the SOAP::Lite documentation, including links to WSDL files.

    Update: Maybe you find this tutorial from the mono project helpuful.
Re: C# client for Soap::Lite
by jfroebe (Parson) on Jun 06, 2005 at 18:55 UTC
Re: C# client for Soap::Lite
by gellyfish (Monsignor) on Jun 06, 2005 at 19:43 UTC

    As others have pointed out, SOAP is designed to interoperate between disparate systems, however it can be relatively difficult to get something working with a server created in a dynamically typed language like Perl and a client in a more strongly typed language such as C# - the temptation to create complex datastructures in Perl for instance can confound the ability to define a class into which it can be deserialized in C#, so the touchstone is to be conservative with the data you are exchanging and to think more in terms of passing documents than objects defined in the respective languages.

    Also the .NET web services framework really does prefer that your services are defined in a WSDL document, so if you are able to create one for your Perl server then you are going to find it easier to create your client using for instance the wsdl tool supplied.

    All that said a C# client for a simple service that just returns a single string is going to be as simple as:

    using System; using System.Web.Services; using System.Web.Services.Protocols; + [System.Web.Services.WebServiceBinding(Namespace="http://tempuri.org/H +ello"), public class Hello : SoapHttpClientProtocol { + public Hello () { this.Url = "http://yoururl/cgi-bin/hello.pl"; } + + [SoapDocumentMethod("http://tempuri.org/Hello/HelloWorld")] public virtual string HelloWorld() { System.Object[] results = this.Invoke("HelloWorld", new object +[0]); return ((string)(results[0])); } + + public static void Main() { Hello foo = new Hello(); Console.WriteLine(foo.HelloWorld()); } }
    Aplogies for the untested non-Perl code. YOur Perl server could be something like:
    #! /usr/bin/perl use strict; use SOAP::Transport::HTTP; + use lib '/var/www/cgi-bin/soap_modules'; + use Hello; + SOAP::Transport::HTTP::CGI -> dispatch_to( 'Hello') -> handle;
    With a Hello.pm that is simply:
    package Hello; + sub HelloWorld { return ("Hello, World"); } + 1;

    /J\

Re: C# client for Soap::Lite
by wolv (Pilgrim) on Jun 06, 2005 at 23:18 UTC

    This isn't a very constructive comment (and I apologize), but I have to say that SOAP is horrible to work with between different languages, implementations and just because of the overall design.

    If your application fits into the REST style, consider using it instead. Unless of course it's not your decision.

    If it is your decision, and your application doesn't fit into REST, consider changing your application.

    Ps. Here's a pretty clear explanation of REST.