Visual Summary: Discussion of SOAP features in. NET Remoting, asp.net Web services, and ATL Web services.
Directory
Brief introduction
Using SOAP as a WEB development tool
Using SOAP as a component development tool
Using SOAP as an ATL development tool
Summarize
Brief introduction
The Microsoft®.net framework and Microsoft®visual Studio.NET leverage XML and SOAP technologies to enable developers to create a broad range of solutions. SOAP is a simple, lightweight, and widely supported protocol for a wide variety of applications, with a simple and natural combination of the. NET Framework.
From the bottom up, SOAP's design goal is to make it a very simple protocol that can meet a variety of different needs in a variety of ways. In addition to Microsoft, many companies have actually applied SOAP, such as IBM, develop Mentor, and userland.
In the system using SOAP, there are several key technologies. When creating a SOAP based solution, each technology solves some common problems with developers. These technologies belong to. NET Remoting, asp.net Web services, and ATL Web services, which have many common technical features:
XML used for message generation and use.
Conforms to the SOAP 1.1 specification, including the 5th section of SOAP encoding, which makes SOAP applications well interoperable.
XML Fidelity (not a 5th-section SOAP encoding) for a fully fractured model.
WSDL (a form of an XML schema) that provides a description.
You can extend a system with a stateless programming model.
A good development environment with Visual Studio.NET.
asp.net Web Services and. NET Remoting also share the following technologies:
XCOPY System deployment.
System.Net, the network communication, whether on the server or the client it is running well.
The common language runtime can be reused in managed code and in the thread buffer pool.
Provides powerful SOAP support, such as SOAP headers and one-way messaging features.
Ability to write applications in conjunction with C #, Visual Basic.NET, or any CLS-compliant language (such as Cobol, Python, componentpascal, and so on).
In addition to the common features and technologies listed above, asp.net Web services,. NET Remoting, and ATL Web Services also provide developers with a number of unique features that help developers grasp the right direction when building applications.
If you want to build. ASP applications, asp.net Web Services:
Allows tight integration with the ASP.net HTTP runtime.
Encourage developers to focus on using XSD data types to provide applications.
Provides strong design support in Visual Studio.NET.
If you are building an mts/com+ application,. NET Remoting:
Provides a comprehensive network fidelity for a controlled code type system.
Provides the ability to pass an object by reference on a network, and can return to a specific object in a particular process.
Provide binary communication capabilities.
If you are building an atl/c++ application, ATL Server:
Provides a flexible and controllable native (c + +) solution.
Built on the ATL Server ISAPI Web Application Architecture (leveraging the thread buffer pool, caching, and so on).
Using SOAP as a WEB development tool
asp.net Web Services provides a RAD way for you to quickly create and use a Web service. These services are loosely grouped together and can be highly integrated with asp.net. asp.net Web Services is the preferred way for Web developers to provide a Web service on the Internet, and its goal is to provide fast, simple, and performance-friendly SOAP services.
asp.net Web services can be deeply integrated with the ASP.net HTTP engine, making it easy for developers familiar with Microsoft Web development technologies to build and use SOAP based Web service.
asp.net provides support for Web Services with the. asmx file. The. asmx file is a text file similar to an. aspx file. These files can be part of an ASP.net application that contains an. aspx file. They can use the URI addressing method, which is the same as the. aspx file.
The following is an example of a very simple. asmx file:
[WebMethod] public String SayHelloWorld () {
Return to "Hello World";
}
}
This file starts with the Web Service indicated by ASP.net and sets the language to C # (you can also set the language to any of the Microsoft Visual basic®, C, or approximately 30 Third-party languages). It then imports the namespace System.Web.Services. This namespace is necessary and you must include it in the file. Next, declare the HelloWorld class. This class is derived from the base class WebService. Finally, any method that is to be accessed as part of the service will have a custom attribute [WebMethod] before their signature, and "<webmethod () >" in Visual Basic.
For this service to take effect, you can name the file helloworld.asmx and place it on the server Foo in the virtual directory Bar. With almost any browser that is compatible with HTML 3.2 or later, you can enter a URL http://Foo/Bar/HelloWorld.asmx to display the common methods for this Web Service (labeled WebMethod properties), and those that can be used to invoke these The protocol for the method, such as SOAP or HTTP get. If you enter Http://Foo/Bar/HelloWorld.asmx?SDL in the Internet Explorer address bar, based on the service Description Language (WSDL) syntax, the same information will be generated for the XML file. This WSDL file is used by the client accessing the service and is very important.
Accessing the Web Serivces
In addition to enabling developers to create Web services technologies, the Microsoft. NET Framework provides a set of sophisticated tools and code for "using" (that is, client-side access) Web services. Because Web services is based on open protocols such as Simple Object Access Protocol (SOAP) and HTTP, this client technology can also be used to use non-asp.net Web services.
There is a tool called WebServiceUtil.exe in the SDK (automatically takes effect when using the "Add Web Reference ..." option in the VS IDE). This program can be used to download the WSDL description of the Web service, and then create a proxy class that represents the address of the service. For example, you can enter:
The system then creates a proxy class called HelloWorld.cs.
This class looks very similar to the class you created earlier. It includes a method called SayHelloWorld, which returns a string. Compiling the proxy class into the application and then calling its methods, the result is that the proxy class packs the SOAP request on HTTP, receives the SOAP-encoded response, and marshals it to a string.
From the client's point of view, the code is very simple:
Dim Myhelloworld as New HelloWorld ()
Dim Sreturn as String = Myhelloworld.sayhelloworld ()
The return value will be "Hello world".
Using SOAP as a component development tool
When you create a distributed application, you can use Microsoft. NET Remoting If you need to be highly controlled and you want to be able to choose the degree of system coupling.
Microsoft. NET Remoting also provides in-depth integration with the common language runtime, and provides developers with a comprehensive cross-connection type system fidelity. This includes constructors, delegates, overloaded methods, passing values and references to objects, hierarchies of classes, interfaces, methods, properties, fields, and applications through pluggable channels, distributed identities, activations, lease lifetimes, and CallContext (stream objects independent of parameters in SOAP headers) on the connection ( Web Services) between Marshal by Value (making a copy) and Marshal by Ref (passing OBJREF).
With. NET Remoting, developers can provide Remoting endpoints from any process, including console applications, GUI applications, NT Service, and IIS. This occurs in any transport that uses a valid load encoding (provided in the product with pluggable serialization formatters and SOAP and binary formatters) through a pluggable channel. Soap=http+xml, which fully supports SOAP 1.1 on HTTP and SMTP, is very satisfying.
We can obtain WSDL support to illustrate the WEB service and guarantee the full fidelity of the Run-time type System.. NET Remoting provides a Soapsuds tool for the. NET SDK, which enables you to generate service descriptions of managed classes and COM objects from metadata. The Soapsuds tool also uses service descriptions and generates metadata and proxies. Developers can use the intensive listening model to insert their actions as application inbound and outbound message flows. Developers who want to be more in-depth can use the binary encoding of TCP channels using sockets.
. NET Remoting enables managed components, native com/com+ components, and serviced components (managed components that use COM + services) to be remoted. These conditions can occur in SOAP, binary, and any type of pluggable channel and format.
Sample: SOAP Managed Code Event
The following code demonstrates how to raise a managed code event between two applications. The client has a local object that is registered as an event notification to receive the remote object. When the client calls the server object, an event is raised to generate a callback to the client local object.
Server-side
Zap.cs
Using System;
Namespace Zap
{
Defining Event Parameters
public class Greetingeventargs:eventargs
{
Public Greetingeventargs (String greeting)
{
this.greeting = greeting;
}
public string greeting;
}
Defining events
public delegate void Greetingevent (object sender,
Greetingeventargs e);
Defining services
public class Waz:marshalbyrefobject
{
This event is scheduled and canceled by the client
public event greetingevent greeting;
Methods that are invoked remotely by the client
public void HelloMethod (string greeting)
{
Console.WriteLine ("Received String {0}", greeting);
Package strings into Greetingeventargs
Greetingeventargs e = new Greetingeventargs (greeting);
Raising an Event
if (greeting!= null)
{
Greeting (this, e);
}
}
}
}
Host.cs
Using System;
Using System.IO;
Using System.Runtime.Remoting;
Using System.Runtime.Remoting.Channels.HTTP;
public class Host
{
public static void Main (string[] args)
{
Manually load the HTTP channel.
This can also be done in the Remoting configuration file.
ChannelServices.RegisterChannel (New HTTPChannel (999));
Registers the server type.
This can also be done in the Remoting configuration file.
Remotingservices.registerwellknowntype (
"Zap",//assembly
"Zap.waz",//Full class name
"Host/waz.soap",//URI
Wellknownobjectmode.singleton); Object mode
Completes the operation, waits for the user to exit
Console.WriteLine (the host is ready to process remote messages.) ");
Console.WriteLine ("Please press ENTER" to exit);
String keystate = Console.ReadLine ();
}
}
Client
Client.cs
Using System;
Using System.Runtime.Remoting;
Using System.Runtime.Remoting.Channels.HTTP;
Using Zap;
To marshal an object locally by reference to the event to be raised
public class Baz:marshalbyrefobject
{
public void Greetinghandler (object sender, Greetingeventargs e)
{
Console.WriteLine ("Greetinghandler Back: Greetings: {0}\n",
e.greeting);
}
}
public class Client
{
public static void Main (string[] args)
{
Baz Baz = new Baz ();
This can also be done in the Remoting configuration file.
Registering the HTTP Channel
ChannelServices.RegisterChannel (new HTTPChannel (0));
Start the Host.exe file in one window, and then start the Client.exe file in another window. You will see that the event is thrown back to the client.
This is a small example of many. NET Remoting applications.. NET Remoting provides a complete CLR managed code type system on the network, and it is a good SOAP server and client because it fully conforms to the SOAP 1.1 specification.
Using SOAP as an ATL development tool
ATL Server Web Services provides C + + developers with an easy way to create and use Web services in native code. ATL Server is the preferred method for C + + developers to provide and use Web Services on the Internet, designed to provide a fast, lightweight, and highly flexible library of Web applications that contain SOAP.
ATL Server is called ATL because it embodies an ATL goal that pursues both high performance and flexibility. For example, you can easily throw away the ATL Server HTTP model, write your own scheduler, and still gain the benefits of ATL Server Marshaling/Protocol code.
ATL Server Web Services uses a syntax specification interface similar to COM to facilitate the learning of current ATL developers. This COM-like syntax allows developers to easily provide objects simultaneously with COM objects and Web Service methods.
The introduction of attributes greatly simplifies the code and makes it easy for non-ATL developers. ATL Server has the ability to interoperate with all other. NET Web Services, which is handy for developers who use multiple technologies in one application.
Interface: The new __interface keyword makes it easy for developers to create COM objects or Web Services interfaces.
This is an example of using ATL Server to define a Web Service interface. With the use of C + + properties, the embedded IDL attribute and the new __interface keyword, ATL Server Web Service interface appear to be very similar to the new attributed COM interface. Here the Web Service Interface sample Iweb_service_exampleservice implements only one method HelloWorld. HelloWorld uses BSTR as input and returns BSTR as output.
Request handler: The request handler is a C + + class that is provided through a handler mapping and has a method provided through an alternative method map. A handler mapping is just a mapping of a literal label to a class name, and a method map is a mapping of a literal label to a method in a class.
[
Request_handler (name= "Default", sdl= "genweb_service_exampleservicesdl"),
Soap_handler (
Name= "Web_service_exampleservice",
Namespace= "Urn:web_service_exampleservice",
protocol= "Soap"
)
]
Class Cweb_service_exampleservice:
Public Iweb_service_exampleservice
{
Public
The ATL Server Request Handler model is very similar to Web applications and Web Services. Figure 1 shows the model for processing the request:
Figure 1. ATL Server Request Processing model
HTTP request goes into IIS, mapping the request (based on the URL and its extensions) to the appropriate ISAPI DLL. The ISAPI DLL then maps the handler specified in the request (that is, the handler specified in the label or query parameter) to the appropriate application DLL. The application DLL then maps this handler to a C + + object. In this model (ATL Server model), the only difference between Web applications and Web Service is the last step. Using a Web services,c++ object to decode/encode SOAP (it inserts the code that performs this action when the compiler resolves the soap_handler property).
You can understand that this class is inherited from our interface, and we use the [Soap_method] property to indicate that the SOAP request will be processed by the HelloWorld method. Implementing this method is the same as implementing any other C + + method.
This Soap_handler property also ensures that the WSDL for a valid description service is automatically generated. Users of the WEB service use this description of the service (formatted as XML/WSDL) to ensure that they can send/receive the correct data in the correct format.
Using Web Services through ATL Server
Using Web Services through ATL Server is relatively straightforward. The developer simply uses the ADD Web Reference dialog box, points it to the. disco file, and then points to WSDL, as it does with other types of Web references. This dialog box runs in the background of the Sproxy.exe utility on the WSDL of the Web Service (there is another utility for a non-native. NET Web Services).
This action creates a Web service proxy file that contains all C + + code that requires the requested WEB service to be exploited. Using the information in the WSDL, the Agent Builder is able to determine what data the Web Service will receive and what data it will return to the client. This allows the Agent builder to create header files that can "talk" to the Web Service.
You only need to create your own Web Service class (as found in the generated header file) and use the appropriate method, such as:
Now you have a basic ATL Server Web service and an ATL Server Web service Consumer.
Summarize
The main purpose of this article is to make a general introduction to the SOAP features in the. NET framework and Visual Studio.NET. Second, give users some useful guidance on how to create an application that uses SOAP.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.