Module 3: Remoting and XML Web Services - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Module 3: Remoting and XML Web Services

Description:

Before calling a remote object, the client registers the channel Channels are ... http://Foo/Bar/HelloWorld.asmx?wsdl. http://Foo/Bar/HelloWorld.asmx. ASP.NET Features ... – PowerPoint PPT presentation

Number of Views:226
Avg rating:3.0/5.0
Slides: 20
Provided by: orasI
Category:

less

Transcript and Presenter's Notes

Title: Module 3: Remoting and XML Web Services


1
Module 3 Remoting and XML Web Services
2
Overview
  • Remoting
  • Remoting Configuration Files
  • XML Web Services

3
Remoting
  • Remoting Overview
  • Channels and Formatters
  • Activation and Proxies
  • Lease-Based Lifetime
  • Object Marshaling
  • Server Side
  • Client Side
  • Client Compilation Techniques

4
Remoting Overview
Client AppDomain
Server AppDomain
Formatter
Formatter
Client Object
Server Object
Channel
Channel
Server Proxy
Remoting Boundary
5
Channels and Formatters
  • Channels Transport Messages To and From Remote
    Objects
  • Client Selects a Channel That Is Registered on
    the Server
  • Before calling a remote object, the client
    registers the channel Channels are registered on
    a per application domain basis
  • One computer cannot have multiple channels
    listening to same port
  • .NET Provides Implementation of HTTP and TCP
    Channels
  • HTTP Channel default SOAP protocol to transport
    XML messages
  • TCP Channel defaultTCP protocol to transport
    binary messages
  • Faster than HTTP SOAP Web Services but not
    as open
  • Example Programmatic Registration of TCP Channel
    on Port 8085

using System.Runtime.Remoting.Channels using
System.Runtime.Remoting.Channels.Tcp TcpChannel
chan new TcpChannel(8085) ChannelServices.Regi
sterChannel(chan)
6
Activation and Proxies
  • Before Using a Remote Object, the Client Must
    Activate It
  • By calling new, Activator.CreateInstance, or
    Activator.GetObject
  • Activation Returns Proxy Used by Client to Access
    Remote Object
  • Proxy represents remote object in clients
    AppDomain
  • Proxy forwards clients calls, and returns
    results and exceptions
  • Server-Side Activation Automatic Instantiation
    by Server
  • Single call object handles only one request
    (stateless)
  • Singleton object services multiple clients and
    requests (stateful)
  • Client-Side Activation Instantiation by
    Explicit Client Call
  • State maintained between method calls for
    specific client instance

7
Object Marshaling
  • Objects Instantiated Remotely Are Returned by
    Reference and Accessed by the Client Through a
    Proxy
  • Remote Call Parameters, Return Values, and Fields
    Can Be
  • Marshal-by-value objects A copy of the object
    is passed from one AppDomain to another
  • - Value types and classes that are serializable
  • Marshal-by-reference objects A reference to the
    object is passed from one AppDomain to another
  • - Classes that derive from the System.MarshalByRef
    Object class
  • Not-marshaled objects Objects suitable for
    local use only
  • - Any class that is not Marshal-By-Value or
    Marshal-By-Reference

8
Server Side
  • Register the Channel
  • Register Remote Objects by Using
  • The RegisterWellKnownServiceType call
  • Or a configuration file

RemotingConfiguration.RegisterWellKnownServiceType
( typeof(HelloServer), "SayHello",
WellKnownObjectMode.SingleCall)
RemotingConfiguration.Configure("MyHello.exe.confi
g")
9
Client Side
  • Register the Channel
  • Activate Remote Object by Using
  • Activator.GetObject
  • new and a configuration file

ChannelServices.RegisterChannel(new
TcpChannel())
HelloServer obj (HelloServer)Activator.GetObject
( typeof(RemotingSamples.HelloServer), "tcp//lo
calhost8085/SayHello")
RemotingConfiguration.Configure("MyHello.exe.confi
g") HelloServer obj new HelloServer()
10
Client Compilation Techniques
  • When the Client Is Compiled, the Compiler Needs
    Server Class Data
  • Class Information Can Be Provided by
  • A reference to the assembly where the class is
    stored
  • Splitting the remote object into an
    implementation class and an interface type
  • Using Wsdl.exe to extract the required metadata
    directly from the endpoint

11
Remoting Configuration Files
  • Configure Method on RemotingConfiguration
  • An Application Configuration File is an XML
    Document
  • Configuration files are case-sensitive
  • Can be specified on a machine or on an
    application level
  • Application level configuration takes
    priority over machine level configuration
  • For more information see Remoting Configuration
    File Format in the .NET Framework SDK
    documentation

RemotingConfiguration.Configure(foo.exe.config)
12
Demonstration Remoting
13
XML Web Services
  • ASP.NET XML Web Services Overview
  • ASP.NET Features
  • Consuming an XML Web Service
  • XML Web Service Discovery

14
What Is an XML Web Service?
A programmable application component accessible
via standard Web protocols
15
ASP.NET XML Web Services Overview
  • ASP.NET Files with .asmx Extensions Are Web
    Services
  • Example of HelloWorld .asmx File
  • If File Is Placed on Server Foo Inside a Virtual
    Directory Bar
  • Access service by using
  • Access WSDL of service by using

lt_at_ WebService Language"C" Class"HelloWorld"
gt using System using System.Web.Services public
class HelloWorld WebService  
WebMethod public String SayHelloWorld()
return "Hello World"
http//Foo/Bar/HelloWorld.asmx
http//Foo/Bar/HelloWorld.asmx?wsdl
16
ASP.NET Features
  • ASP.NET Can Expose Web Services Defined in a .NET
    Class
  • Class derives from WebService, method attribute
    WebMethod
  • Class source file is compiled into a library DLL
    and placed in \Bin
  • The .asmx file contains a single line that names
    the class
  • Advanced ASP.NET Features
  • Data sets, Global.asax, Session and Application
    objects, pattern matching

namespace MyNameSpace public class HelloWorld
WebService WebMethod public String
SayHelloWorld() return "Hello
World"
csc /outbin\helloworld.dll /tlibrary
helloworld.cs
lt_at_ WebService Class"MyNameSpace.HelloWorld" gt
17
Demonstration Using Visual Studio .NET to Create
an XML Web Service
18
Consuming an XML Web Service
  • To Consume a Web Service, Use Wsdl.exe
  • Identify the object or service URI to be used
  • Run Wsdl.exe on the services URI
  • Write the client code that calls the remote
    object
  • Build the client and proxy code

http//localhost/MathService/Service1.asmx
wsdl http//localhost/MathService/Service1.asmx?ws
dl
Service1 salesTaxService new Service1() float
totalAmount salesTaxService.SalesTax( amount,ta
xRate)
csc salestaxclient.cs service1.cs
19
XML Web Service Discovery
  • Discovery The Process of Locating and
    Interrogating XML Web Service Descriptions
  • Discovery Services Are Evolving and Changing
    Rapidly
  • Disco Microsoft XML Web Services Discovery Tool
  • Disco file is an XML document that links to
    descriptions of XML Web Services
  • Disco file is currently created and used by
    Visual Studio
  • Universal Description, Discovery, and Integration
    Project
  • Open framework for describing services,
    discovering businesses, and integrating business
    services that use the Internet
  • Cross-industry support and platform independence
  • For more information, see http//www.uddi.org
Write a Comment
User Comments (0)
About PowerShow.com