Loading ...
Sorry, an error occurred while loading the content.

Re: Building a .NET Client

Expand Messages
  • kgoess
    ... You can also code the thing up in C# without using WSDL. Here s a sort of template to get you started. It is a GarciaClient class which you can ask for a
    Message 1 of 3 , Feb 24, 2006
      --- In soaplite@yahoogroups.com, Matt Long <matt.long@...> wrote:
      > You really just have to create your own WSDL. It's not too
      > hard, but there is a learning curve.

      You can also code the thing up in C# without using WSDL. Here's a
      sort of template to get you started. It is a GarciaClient class
      which you can ask for a garciaProxy object. You populate the
      garciaProxy object with the fields you want and tell the
      GarciaClient to send it off to the "methodGarcia" SOAP method on the
      perl server.

      I haven't tested this particular code very far, though it does seem
      to run ok. Hope this helps.

      using System;
      using System.Web.Services.Protocols;
      using System.Web.Services;
      using System.Collections.Specialized;
      using System.Runtime.Serialization.Formatters.Soap;

      using System.Xml;
      using System.Xml.Serialization;

      using System.Net;
      using System.Security;
      using System.Security.Cryptography.X509Certificates;

      using System.Reflection;

      namespace acme.com {

      ///This class encapsulates the SOAP transactions with the
      ///Acme servers.
      public class GarciaClient :
      System.Web.Services.Protocols.SoapHttpClientProtocol {

      /// After methodGarcia, this has the status message from the
      public String statusMessage = "";

      /// After methodGarcia fails, this will contain
      /// the exception object, possibly a
      /// System.Web.Services.Protocols.SoapHeaderException
      /// or a
      /// System.Web.Services.Protocols.SoapException
      public Exception exceptionObject = null;

      /// After methodGarcia succeeds, this will contain a
      /// GarciaProxy object populated with the return data
      /// from the Acme server, you can query it for items
      public GarciaProxy garciaProxyReturned = new GarciaProxy();

      /// Constructor, defaults superclass's member <c>Url</c> to
      /// "https://www.acme.com/garcia-soap/";
      public GarciaClient(){
      this.Url = "https://www.acme.com/garcia-soap/";

      /// This is the external method. First you
      /// get a garcia proxy object via getGarciaProxy(),
      ///then you populate its members, then you give it to this
      ///<param name="garciaProxy"> a GarciaProxy object, see
      ///true or false for success or failure
      ///Using a boolean return code rather than throwing an
      exception in an
      ///attempt to keep the asp code simpler.
      ///The <c>statusMessage</c> and <c>exceptionObject</c> are
      lodged in the GarciaClient
      public bool methodGarciaProxy(GarciaProxy garciaProxy){

      Boolean rc = true;

      //make sure everything is zeroed out
      this.statusMessage = "";
      this.exceptionObject = null;
      this.garciaProxyReturned = new GarciaProxy();

      try {

      this.garciaProxyReturned =

      rc = true;

      }catch (Exception e){
      this.statusMessage = e.Message;
      this.exceptionObject = e;
      rc = false;
      return rc;

      /// This is the <b>internally-called</b> SOAP method. It
      needs to
      /// be public for the soap reflection stuff to work, but you
      /// probably don't want to call it.
      /// a GarciaProxy struct with its members populated.
      // Literal depends on the WSDL to get the type
      // Encoded has the type information embedded

      public GarciaProxy methodGarcia(GarciaProxy garciaProxy){

      object[] results = this.Invoke("methodGarcia",
      new object[]{garciaProxy
      //Console.WriteLine("methodGarcia results is
      "+results[0]); //DEBUG
      return ((GarciaProxy)(results[0]));

      /// Here's a main for testing
      public static int Main(string[] args){

      if (args.Length < 3) {
      Console.WriteLine("usage: GarciaClient <url> <name>
      <phone> " );
      return 1;

      GarciaClient sc = new GarciaClient();

      //sc.Url = "https://www.acme.com/testing-garcia-soap/";
      sc.Url = args[0];

      GarciaProxy gp = new GarciaProxy();

      gp.name = args[1];
      gp.phone = args[2];
      gp.services = new string[] {"5","6","11","12"};

      if (sc.methodGarciaProxy(gp)){

      GarciaProxy results = sc.garciaProxyReturned;

      Console.WriteLine("No problem, the serverdata is: " +
      for (int i = 0; i < results.services.Length; ++ i) {
      Console.WriteLine("\tservice # "+i+" is " +
      Console.WriteLine("Error: " +
      return 0;

      /// This is a proxy object, call getGarciaProxy() to get
      /// then populate its fields with the correct values, and
      /// then give it to methodGarciaProxy(GarciaProxy)
      public class GarciaProxy {

      public String name = "";

      public String phone = "";

      public String serverdata = "";

      public string[] services = new string[0];


      } //end namespace
    Your message has been successfully submitted and would be delivered to recipients shortly.