Click here to Skip to main content
Licence 
First Posted 17 Jan 2006
Views 26,787
Bookmarked 13 times

Soapsuds.exe -- Imp. Tool (.Net Framework Tools Series)

By | 17 Jan 2006 | Article
Soapsuds.exe -- Imp. Tool (.Net Framework Tools Series)

Soapsuds.exe -- Imp. Tool (.Net Framework Tools Series)

Today we gonna discuss Soapsuds tool.

Soapsuds is shipped with .Net Framework and is used by .Net remoting Client Applications to generate xml schema, proxy class or assembly for there HTTP Remoting Server. Client App can use this proxy class or assembly as a reference to the remoting server object.

Confused???

Let us take an example and look into it.

Step 1: Create a remoting HTTP server.
Step 2: Generate WSDL for HTTP Server using IE.
Step 3: Use soapsuds to create proxy class, xml schema and assembly.
Step 4: Crete a remoting client that uses the proxy class or assembly.   
Step 5: Checking out some imp options of soapsuds.

Step 1:

1) Create a new console application called Remoting Server.
2) Add a class called Calc, which will hold our calculation services.
3) Our Calc class should be inherited from "MarshalByRefObject"
4) Add four methods to this class Add, Del, Mul, Div as shown in the code below.
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class Calc:MarshalByRefObject
{
           public int Add(int i , int j)
            {
                    return i+j;
            }
            public int Del(int i , int j)
            {
                    return i-j;
            }
            public int Mul(int i , int j)
            {
                    return i*j;
            }
            public int Div(int i , int j)
            {
                    return i/j;
            }
}
5) Add another class called ClassMain which will hold function Main() as follows :
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

class ClassMain
{
          /// <summary>
          /// The main entry point for the application.
          /// </summary>
          [STAThread]
          static void Main(string[] args)
          {
            HttpChannel httpChannel = new HttpChannel(8765);
            ChannelServices.RegisterChannel(httpChannel);
            RemotingConfiguration.ApplicationName ="MyRemotingApp";
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Calc),"MyCalc",WellKnownObjectMode.Singleton);
            Console.WriteLine("Server started ..... ");
            Console.ReadLine();
          }
}

6) Our Http Remoting Server is now ready which will work on port 8765. This is a Singleton server i.e. only object will be  created and this object will server to all the clients.

7) Compile the application and create the executable.

8) Run the executable and you should get a message "Server started". The server executable should be running hence forth throughout the example.

Step 2:

1) Open IE and type the below link to generate the WSDL.
     <A href="http://localhost:8765/MyRemotingApp/MyCalc?WSDL" target=_top>http://localhost:8765/MyRemotingApp/MyCalc?WSDL</A>

Step 3:

1) See that the server is running (Run the executable).

2) Go to the VS.NET command prompt and type soapsuds /? . This will list all the available options.

Input Sources (only one can be specified)
-urlToSchema(-url):[SchemaUrl]
-types:[type1,assemblyname[,serviceEndpoint]][;type2,assemblyname[,serviceEndpoint]][...]
-inputSchemaFile(-is):schemafile Input Schema File
-inputAssemblyFile(-ia):assemblyfileInput Options
-inputDirectory(-id):directory     Location of input dlls.
-serviceEndpoint(-se): Url for Service Endpoint placed in Wsdl file
Output Options
-outputSchemaFile(-os):schemafile
-outputDirectory(-od):directory for generated source files
-outputAssemblyFile(-oa):assemblyfile
Generate Options
-GenerateCode(-gc)  (equivalent to "-od:.")
Other Options
-WrappedProxy(-wp) Create wrapped proxy (default)
-NoWrappedProxy(-nowp)   No wrapped proxy
-proxyNamespace(-pn)  Namespace on generated proxy (Only used for interopNamespaces)
-StrongNameFile(-sn):filename   Use strong name to build assembly
Connection Information Options
-username(-u):username
-password(-p):password
-domain(-d):domain
-httpProxyName(-hpn):name
-httpProxyPort(-hpp):number

Note : After these options there are some examples given about the usuage of the tool. Check them out.

3) -url := URL , -gc := Generate Code, oa:= output assembly and os:output schema are few important options that we will be  using.

4) Now we will generate code (proxy class),proxy assembly and xml schema for our remoting server.

5) Lets generate code using for our remoting http server using the server URL. We will using this further with our client application to reference our remoting server. The below code should generate a class named Remotingserver.cs .
    soapsuds -url:<A href="http://localhost:8765/MyRemotingApp/MyCalc?WSDL" target=_top>http://localhost:8765/MyRemotingApp/MyCalc?WSDL</A> -gc
6) After generating code now we will create an assembly named MyServer.dll for our http remoting server.
    soapsuds -url:<A href="http://localhost:8765/MyRemotingApp/MyCalc?WSDL" target=_top>http://localhost:8765/MyRemotingApp/MyCalc?WSDL</A> -oa:MyServer.dll
7) Now we will generate xml schema for our server object.
    soapsuds -url:<A href="http://localhost:8765/MyRemotingApp/MyCalc?WSDL" target=_top>http://localhost:8765/MyRemotingApp/MyCalc?WSDL</A> -os:MyServer.xmlStep 4:
1) Create an client console application which will communicate with our server.
2) Add Class called Client.cs and in the Main write code to communicate with our server object.
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using RemotingServer;

namespace RemotingClient
{
       /// <summary>
       /// Summary description for Client
       /// </summary>
       class Client
       {
               /// <summary>
               /// The main entry point for the application.
               /// </summary>
               [STAThread]
               static void Main(string[] args)
               {

                 HttpChannel httpChannel = new HttpChannel();
                 ChannelServices.RegisterChannel(httpChannel);
                 RemotingServer.Calc obj = new Calc();
                 obj =(RemotingServer.Calc)Activator.GetObject(typeof(RemotingServer.Calc),                     "<A href="http://localhost:8765/MyRemotingApp/MyCalc" target=_top>http://localhost:8765/MyRemotingApp/MyCalc</A>");
                 Console.WriteLine(((RemotingServer.Calc)obj).Add(1,2));
                 Console.ReadLine();
               }
       }
}

3) In this we are opening an HTTP channel to communicate with our remote object. Our remote object is a SAO i.e. Server activated
object. Finally we are calling the Add function, which should return us 3.

4) First we will add our proxy class i.e. RemotingServer.cs to our application. Add compile the project.

Note: There should not be any reference to any remoting server dll's in our project. The only addition should be Remoting server  class, which will communicate with the remote object.

5) Result 3 should be displayed.

6) Stop the application and remove the proxy class RemotingServer.cs. NOW ADD reference to MyServer.dll and compile the project and execute it.

7) Result 3 should be displayed.

8) This way we can use either the proxy class or the proxy dll to communicate with our remoting object.

Step 5 :

Let us now check out some other important options of soapsuds.

1) Generating xml schema, assembly and code for a particular type in the assembly.

       soapsuds -types:Calc.MyServer,MyServer -gc
       soapsuds -types:RemotingServer.Calc,MyServer -os:MyCalc.xml
       soapsuds -types:RemotingServer.Calc,MyServer -oa:MyCalc.dll
2) Generating code and assembly from xml schema.
       soapsuds -is:MyServer.xml -gc
       soapsuds -is:MyServer.xml -oa:MyServer1.dll
3) You can reference these in your client application.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Namratha Shah

Architect

United States United States

Member

Namratha Shah a.k.a. Nasha is from orginally from Bombay, India but currently residing NJ, USA. She has to her credit, a Bachelor’s Degree in Microbiology and Biotechnology and a Master's in Computer and Software Applications (1999-2001) from Somaiya College Bombay. She started her career with C and C++ and then moved on to Microsoft Technologies. She has over 7.5 years experience in software architecture, design and development. She is a Certified Scrum Master and a member of the CORE .NET Architecture team. She has been Awarded with Microsoft’s Prestigious Most Valuable Professional (MVP) twice consecutively in years 2005 and 2006 in Visual C#.NET for her outstanding contributions to the .NET community.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThe remote server returned an error: (401) Unauthorized. Pinmembertprakash22:57 29 Mar '07  
Questioncompile error with Client.cs Pinmembermstramba22:03 4 May '06  
AnswerRe: compile error with Client.cs PinmemberSamprayoga4:11 5 Jul '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 17 Jan 2006
Article Copyright 2006 by Namratha Shah
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid