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
    • 0 Attachment
      --- 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 {

      ///<remarks>
      ///This class encapsulates the SOAP transactions with the
      ///Acme servers.
      ///</remarks>
      [System.Web.Services.WebServiceBindingAttribute(
      Name="AcmeSoapProxy",
      Namespace="urn:www.acme.com")]
      public class GarciaClient :
      System.Web.Services.Protocols.SoapHttpClientProtocol {


      ///<summary>
      /// After methodGarcia, this has the status message from the
      server.
      ///</summary>
      public String statusMessage = "";

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

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


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


      ///<summary>
      /// 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
      method.
      ///</summary>
      ///<param name="garciaProxy"> a GarciaProxy object, see
      <c>getGarciaProxy()</c></param>
      ///<returns>
      ///true or false for success or failure
      ///<para>
      ///Using a boolean return code rather than throwing an
      exception in an
      ///attempt to keep the asp code simpler.
      ///</para>
      ///The <c>statusMessage</c> and <c>exceptionObject</c> are
      lodged in the GarciaClient
      ///</returns>
      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 =
      this.methodGarcia(garciaProxy);

      rc = true;

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

      ///<summary>
      /// 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.
      ///</summary>
      ///<returns>
      /// a GarciaProxy struct with its members populated.
      ///</returns>
      ///<exception
      cref="System.Web.Services.Protocols.SoapHeaderException">
      ///</exception>
      ///<exception
      cref="System.Web.Services.Protocols.SoapException">
      ///</exception>
      [System.Web.Services.Protocols.SoapDocumentMethodAttribute(
      "urn:www.acme.com/methodGarcia",
      RequestNamespace="urn:www.acme.com",
      ResponseNamespace="urn:www.acme.com",
      // Literal depends on the WSDL to get the type
      information
      //Use=System.Web.Services.Description.SoapBindingUse.Literal,
      // Encoded has the type information embedded
      Use=System.Web.Services.Description.SoapBindingUse.Encoded,

      ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped
      )]
      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]));
      }

      ///<summary>
      /// Here's a main for testing
      ///</summary>
      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: " +
      results.serverdata);
      Console.WriteLine("Services:
      ["+results.services.Length+"]");
      for (int i = 0; i < results.services.Length; ++ i) {
      Console.WriteLine("\tservice # "+i+" is " +
      results.services[i]);
      }
      }else{
      Console.WriteLine("Error: " +
      sc.statusMessage);
      }
      return 0;
      }
      }


      ///<summary>
      /// This is a proxy object, call getGarciaProxy() to get
      one,
      /// then populate its fields with the correct values, and
      /// then give it to methodGarciaProxy(GarciaProxy)
      ///</summary>
      [System.Xml.Serialization.SoapTypeAttribute("GarciaProxy",
      "urn:www.acme.com/encodedTypes")]
      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.