all groups > dotnet myservices > november 2004 >
You're in the

dotnet myservices

group:

Article : Soapsuds.exe (.Net Framework tools series)


Article : Soapsuds.exe (.Net Framework tools series) Namratha Shah \(Nasha\)
11/26/2004 9:30:29 PM
dotnet myservices:
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 their HTTP
Remoting Server. Client App can use this proxy class or the 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 which 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",Wel
lKnownObjectMode.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 throughout hence forth.

Step 2:

1) Open IE and type the below link to generate the WSDL.

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

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

Step 3:

1) See that the server is runnning (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[,serviceEn
dpoint]][...]
-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 uning the server
URL. We will using this further wth 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.d
ll

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

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

Step 3:

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
Re: Article : Soapsuds.exe (.Net Framework tools series) Lars-Inge Tønnessen [VJ# MVP]
12/2/2004 7:20:38 PM

Please upload those articles to the Codeproject. On the Codeproject they are
searchable etc... =:o)

http://www.codeproject.com/



Regards,
Lars-Inge

AddThis Social Bookmark Button