New Message on dotNET User Group Hyd

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

Reply
  Reply to Sender   Recommend Message 1 in Discussion
From: Nasha

Hey Group,

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.

      
http://localhost:8765/MyRemotingApp/MyCalc?WSDL

I have attached MyCalc.xml file with this mail. You check out the generated WSDL.

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):assemblyfile

Input 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:
http://localhost:8765/MyRemotingApp/MyCalc?WSDL -gc

6) After generating code now we will create an assembly named MyServer.dll for our http remoting server.

    soapsuds -url:
http://localhost:8765/MyRemotingApp/MyCalc?WSDL -oa:MyServer.dll

7) Now we will generate xml schema for our server object.

    soapsuds -url:
http://localhost:8765/MyRemotingApp/MyCalc?WSDL -os:MyServer.xml

Step 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),                 
    "http://localhost:8765/MyRemotingApp/MyCalc");
                       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.



-- Please post your queries and comments for my articles in the user group for the benefit of all. I hope this step from my end is helpful to all of us.

Regards,

Namratha (Nasha)
<o:p></o:p>

View Attachment(s)

View other groups in this category.

Click Here!
Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to