10.3 Using Web Services from .NET Remoting

only for RuBoard

To get the best of both worldsthat is, cross-platform compatibility and performanceyou can access web services from .NET remoting. Imagine a scenario in which a service is not only provided to the world at large, but internallywithin the company providing it. There is no reason why the internal clients should suffer from potential performance problems and implementation limitations because the objects they need are web services.

Achieving this compatibility takes little effort. Just add an additional attribute to the web method to let it know that RPC-encoding is needed. The attribute is called SoapRpcMethodAttribute , and it is applied like this:

 <SoapRpcMethod( ), _  WebService(Namespace:="http://www.mydomainhere.com/")> _ Public Class ZipService : Inherits MarshalByRefObject 

Additionally, the class needs to derive from MarshalByRefObject . If not, SoapSuds generates the wrong type of proxy.

10.3.1 Configuration

A Web.config file must be provided for the web service (placed into the ZipService virtual directory) to register any channels that might be needed and to define well-known object entries. In Example 10-4, a TCP channel is configured to listen on port 1969 and a Singleton that is accessible at ZipService.soap is specified for ZipService .

Example 10-4. Web.config for ZipService
 <configuration>   <system.runtime.remoting>     <application>       <channels>         <channel ref="tcp" port="1969" />       </channels>       <service>         <wellknown mode="Singleton"                     type="ZipService,ZipService"                     objectUri="ZipService.soap" />       </service>     </application>   </system.runtime.remoting> </configuration> 

10.3.2 Creating the Proxy

Now that the Web.config is place, SoapSuds can be used to generate a proxy. Do not use the URL to ZipService.asmx . Instead, use the URL that includes the objectUri attribute from Web.config . Remember, the URL is formed from the machine name (or IP address), the virtual directory, and the objectUri attribute from the well-known entry in the configuration file, with ?wsdl appended:

 soapsuds -url:http://192.168.1.100/ZipService/ ZipService.soap?wsdl -oa:ZipServiceProxy2.dll 

10.3.3 The Client

The client, shown in Example 10-5, is similar to most clients from Chapter 9, but with a small variation. Rather than using a configuration file to specify a channel, the channel is registered programmatically.

Example 10-5. Remoting client to web service
 'vbc /t:exe /r:System.Runtime.Remoting.dll  '/r:ZipServiceProxy2.dll remoteclient.vb     Imports System Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels     Public Class RemotingClient       Public Shared Sub Main( )         Try           Dim tcp As New Tcp.TcpChannel(1969)       ChannelServices.RegisterChannel(tcp)  Dim zs As New ZipService( )  'Or       'Dim zsObj As Object = Activator.GetObject(GetType(ZipService), _       '  "tcp://192.168.1.100:1969/ZipService/ZipService.soap")       'Dim zs As ZipService = CType(zsObj, ZipService)           Console.WriteLine(zs.IsValid("Houston", "77002"))         Catch e As Exception       Console.WriteLine(e.ToString)       Console.WriteLine(e.Message)     End Try         Console.WriteLine("Press ENTER to continue...")     Console.ReadLine( )       End Sub     End Class 

To verify that the TCP channel is in fact used, forgo transparent activation and test it by using Activator.GetObject with "tcp."

only for RuBoard


Object-Oriented Programming with Visual Basic. Net
Object-Oriented Programming with Visual Basic .NET
ISBN: 0596001460
EAN: 2147483647
Year: 2001
Pages: 112
Authors: J.P. Hamilton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net