How to install and use the web service dispatcher?

Perquisites
 .NET framework
  Microsoft Soap Toolkit 3.0
(you can still use Microsoft Soap Toolkit 2.0 by modifying the web.config file).

Following steps for install web service dispatcher :-

Step 1. First, unzip the file WebServiceDispatcher.zip into a directory on the target machine, you need to preserve directory structure while unzipping.

Step 2. Create a virtual web directory WebServiceDispatcher pointing to the above directory.

Then we need to register existing web methods with the dispatcher.

Step 3.
Call the RegisterMethod method of the dispatcher.

The RegisterMethod method does not have to be called by the server instance that implements the web method, but typically a server calls RegisterMethod to register its web methods when starting up. The following VB script registers a web method named GetData .

Option Explicit

Const WSDL_URL = _
 "http://localhost/WebServiceDispatcher/ServiceDispatcher.asmx?wsdl"
Const INPUT_XML = _
   "<Root><MethodList><Method>_
   <MethodName>GetData</MethodName>_
   <ProviderName>Server11</ProviderName>_
   <ServiceURL>http://Server11.com/MyService/MyService.wsdl</ServiceURL>_
   </Method></MethodList></Root>"

Dim spclt
Set spclt = CreateObject("MSSOAP.SoapClient")
spclt.mssoapinit WSDL_URL

If spclt.RegisterMethod(INPUT_XML) Then
   WScript.Echo "Web method registered"
Else
   WScript.Echo "Failed to register web method"    
End If
set spclt = nothing

Here is an example of the input string to the RegisterMethod method. As you can see, it is possible to register multiple web methods with one call.


<Root>
  <MethodList>
      <Method>
           <MethodName>GetName</MethodName>
           <InternalMethodName>GetName1</InternalMethodName>
           <ProviderName>NameProvider1</ProviderName>
           <ServiceURL>http://NameProvider1.com/WebService/WebService.wsdl
           </ServiceURL>
           <ProxyServer>MyProxy.Com</ProxyServer>
           <ProxyPort>91</ProxyPort>
           <AuthUser>Tester</AuthUser>
           <AuthPassword>123456</AuthPassword>
      </Method>
      <Method>
           <MethodName>GetName</MethodName>
           <InternalMethodName>GetName2</InternalMethodName>
           <ProviderName>NameProvider2</ProviderName>
           <ServiceURL>http://NameProvider2.com/WebService/WebService.wsdl
           </ServiceURL>
           <ProxyServer>MyProxy.Com</ProxyServer>
           <ProxyPort>91</ProxyPort>
           <AuthUser>Tester</AuthUser>
           <AuthPassword>123456</AuthPassword>
       <Method>
       <Method>
           <MethodName>GetAge</MethodName>
           <ProviderName>AgeProvider</ProviderName>
           <ServiceURL>http://AgeProvider.com/WebService/WebService.wsdl
           </ServiceURL>
       </Method>
   </MethodList>
</Root>

The <MethodName> string identifies the web method registered on the dispatcher. The <ProviderName> string identifies a server instance that implements this web method. The <InternalMethodName> string is the name of the web method on the server instance that implements it, you can register the same web method from two different server instances (two different providers) as demonstrated in the above XML. It is assumed that <MethodName> and <InternalMethodName> are the same in case <InternalMethodName> is not provided. When a request to invoke a web method comes to the dispatcher, the dispatcher will randomly pick a provider if there is more than one. The <ServiceURL> string is used by the dispatcher to access the provider of a web method on behalf of the clients. The <ProxyServer> and the <ProxyPort> strings are optional, they are needed only if there is a firewall between the dispatcher and the provider of the web method. The <AuthUser> and the <AuthPassword> strings are also optional, they are needed only if access to the web method provider are restricted by the given user name and password.

It is ok to register a web method for the same provider more than once, the last registeration will override the previous ones. For example, if the <ServiceURL> string was wrong when it was first registered, you can correct the information by registering it again.

A server providing a web method through the dispatcher should call the UnRegisterMethod method before shutting down itself. The format of the input string for UnRegisterMethod is the same as that of the RegisterMethod except that you need only to specify <MethodName> and <ProviderName> . If you don't specify <ProviderName> , then the web method identified by <MethodName> will be unregistered for all providers!

Step 4.
Other programs access the registered web methods by calling InvokeMethodX methods of the web service dispatcher.

Here is a VB script that calls the GetData web method registered in the above script, assuming it takes only one input argument.

Option Explicit

Const WSDL_URL = _
 "http://localhost/WebServiceDispatcher/ServiceDispatcher.asmx?wsdl"

Dim spclt
Set spclt = CreateObject("MSSOAP.SoapClient")
spclt.mssoapinit WSDL_URL

Dim output
output = spclt.InvokeMethod1("GetData", "This is an input string")

If output <> "" Then
   WScript.Echo "Output: " & output
Else
   WScript.Echo "Failed to invoke web meothod"
End If

set spclt = nothing

When writing real code, you should know what to send as the input arguments and how to process the output. I have included code for a sample web service called MathService which provides four web methods, Add, Subtract, Multiply, and Divide . To install MathService , you need to unzip the MathService.zip file into a directory on the target machine and create a virtual web directory named MathService for it. Run the script RegisterMathService.vbs to register methods of MathService on the dispatcher (assuming you already installed the dispatcher). Run the script InvokeMathService.vbs to invoke the methods of MathService through the dispatcher.

2 comments:

  1. Hi

    I read this post two times.

    I like it so much, please try to keep posting.

    Let me introduce other material that may be good for our community.

    Source: Dispatcher interview questions

    Best regards
    Henry

    ReplyDelete
  2. Hi

    Tks very much for post:

    I like it and hope that you continue posting.

    Let me show other source that may be good for community.

    Source: Dispatcher interview questions

    Best rgs
    David

    ReplyDelete