Microsoft .NET framework and SOAP in Visual Studio.net

zhaozj2021-02-08  392

Keith Ballinger, ASP.NET Web Services Project Planning Manager Jonathan Hawkins, .NET Remoting Project Planning Manager PRANISH KUMAR, ATL Server Project Planning Manager

Microsoft Corporation

Summary: Discussion on SOAP feature in .NET Remoting, ASP.NET Web Services and ATL Web Services.

table of Contents

Introduction to use SOAP as a web development tool to use SOAP as component development tools to use SOAP as ATL development tool summary

Introduction

Microsoft® .NET Framework and Microsoft® Visual Studio.net utilize XML and SOAP technology to enable developers to create a wide range of solutions. SOAP is a simple, lightweight, and has a widely supported protocol for a wide range of applications, which is naturally natural with the combination of .NET framework

Starting from the bottom, SOAP design goals are to make it a very simple protocol that can meet a variety of different needs in a variety of different ways. In addition to Microsoft, there are many companies actually apply SOAP, such as IBM, Develop Mentor, and Userland.

There are several key technologies in the system using SOAP. Each technology resolves some common issues of developers when creating a SOAP-based solution. These technologies belong to .NET Remoting, ASP.NET Web Services, and ATL Web Services, which have many common technical features:

Used for messages generation and use XML. Compliance with the SOAP 1.1 specification, including section 5 SOAP encoding, which makes the SOAP application have good interoperability. XML fidelity (non-Section 5 SOAP encoding) for a fully disconnected model. A form of WSDL (XML scheme) is used to provide instructions. The stateless programming model extension system can be used. Use Visual Studio.NET to develop a good development environment.

ASP.NET Web Services and .NET Remoting also share the following technologies:

Xcopy system deployment. System.net, when network communication, whether it is in the server or the client it runs well. The public language can be reused in the controlled code and the thread buffer pool. Provide powerful SOAP support, such as features such as SOAP headers and one-way messages. Ability to use C #, Visual Basic.NET or any language that meets CLS specifications (such as COBOL, PYTHON, ComponentPascal, etc.) to write applications.

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, which helps developers grasp when generating applications. right direction.

If you want to generate .asp applications, ASP.NET Web Services:

Allows tight integration with ASP.NET HTTP runtime. Encourage developers to focus on the use of XSD data types to provide applications. Provide powerful design support in Visual Studio.NET.

If you want to generate the MTS / COM application, .NET Remoting:

Provide a comprehensive network fidelity for a comprehensive controlled code type system. Provides the functionality of the object by reference to the network, and can return to a specific object in a particular process. Provide binary communication capabilities.

If you want to generate an ATL / C app, ATL Server: provides flexible and controllable native (C ) solutions. It is built on the ATL Server ISAPI web application system (using thread buffer pool, cache, etc.).

Use SOAP as a web development tool

ASP.NET Web Services provides RAD way for fast creation and use of web services. These services are easily combined and can be integrated with ASP.NET. ASP.NET Web Services is the preferred method for web developers to provide web services on the Internet. Its goal is to provide fast, simple, superior SOAP services.

ASP.NET Web Services can be integrated with the ASP.NET HTTP engine, making developers familiar with Microsoft Web development technologies to easily generate and use SOAP-based web services.

ASP.NET provides support for Web Services with .asmx files. The .asmx file is a text file similar to the .aspx file. These files can be part of the ASP.NET application that contains .aspx files. They can use the URI addressing method, which is the same as the .aspx file.

The following is a very simple .asmx file example:

<% @ Webservice Language = "C #" class = "HelloWorld"%>

Using system;

Using system.Web.services;

Public class helloworld: WebService {

[WebMethod] public string Sayhelloworld () {

Return "Hello World";

}

}

This file begins with the web service indicated by ASP.NET and sets the language to C # (or any one of Microsoft Visual Basic®, C, C or about 30 third-party languages). Then, it will import namespace system.web.services. This name space is necessary, you must include it in the file. Next, declare the HelloWorld class. This class is exported from the base class WebService. Finally, any method to be accessed as part of the service will have custom properties [WebMethod] before their signature, "" in Visual Basic.

To make this service take effect, you can name HelloWorld.asmx, then place it on the server foo in the virtual directory bar. Using almost any browser that is compatible with HTML 3.2 or higher, you can enter URL http: //foo/bar/helloworld.asmx to display this Web Service's utility (marked with webmethod attribute), and those available to call these The protocol of the method, such as SOAP or HTTP GET. If you enter http: //foo/bar/helloWorld.asmx? SDL in the Internet Explorer address bar, the same information as the XML file is generated based on the Service Description Language (WSDL) syntax. This WSDL file is used by customers who access services and is very important.

Visit Web Servces

In addition to making developers to create Web Services, the Microsoft .NET framework also provides a mature tool and code for "use" (ie client identity) 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 (using the "Add Web Reference ..." option in VS ID). This program can be used to download the WSDL description of the Web Service and then create an agent class representing the address of this service. For example, you can enter:

Webserviceutil / c: proxy /pa: http://somain.com/somefolder/helloWorld.asmx?sdl

Then, the system will create a proxy class called HelloWorld.cs.

This class looks very similar to the classes created in front. It includes a method called SayHelloWorld that returns a string. Compile this proxy class into the application, then call its method, the result is that the proxy class packages the SOAP request on HTTP and receives the response of the SOAP encoding, and then sealed as a string.

From the client, the code is very simple:

Dim myhelloworld as new helloworld ()

Dim sreturn as string = myhelloworld.sayhelloWorld ()

The return value will be "Hello World".

Use SOAP as components development tools

When you create a distributed application, you can use Microsoft .NET Remoting if you need a high degree of control and require the system coupling.

Microsoft .NET Remoting also provides in-depth integration with public language, and provides developers with a comprehensive cross-connection type system fidelity. This includes constructor, commission, overloading methods, via values ​​and references to deliver objects, class hierarchies, interfaces, methods, properties, fields, and through plug-in channels, distributed identifiers, activation, rental life, and CallContext. The flow object in the parameter SOAP header) Marshal by Value between the application (Web Services) and the Marshal By Ref (Pass ObjRef).

Using .NET Remoting, developers can provide Remoting endpoints from any process, including console applications, GUI applications, NT Service, and IIS. This happens in any use of effective loading encoding (providing an insertable serialization formatting program in the product and the SOAP and binary formatting programs). SOAP = HTTP XML, which fully supports SOAP 1.1 on HTTP and SMTP, which is very satisfactory.

We can get WSDL support to explain the Web Service and ensure the full fidelity of the runtime system. .NET Remoting provides the .NET SDK's SOAPSUDS tool that generates a service description of the control class and COM object from the metadata. The SOAPSUDS tool also uses service instructions and generates metadata and proxy. Developers can use dense listening models to insert their operations as an application inbound and outbound message flow. Think more in-depth developers can use a binary code TCP channel using a socket.

.NET Remoting Remotely remotely enables controlled components, native COM / COM components, and components that accept services (controlled components using COM services). These situations may occur in SOAP, binary, and any insertable channels and formats. Sample: SOAP controlled code event

The following code demonstrates how to trigger a controlled code event between two applications. The client has a local object that is registered as an event notification for receiving a remote object. When the client calls server object, events raise events to generate a call to the client's local object.

Service-Terminal

Zap.cs

Using system;

Namespace ZAP

{

/ / Define event parameters

Public Class GreetingEventAntargs: Eventargs

{

Public GreetingEventArgs (String Greeting)

{

THIS.GREETING = Greeting;

}

Public string greeting;

}

/ / Define events

Public Delegate Void GreetIndevent (Object Sender,

GreetingEventArgs E);

// Define services

Public Class WAZ: MarshalByrefObject

{

// Client will book and cancel this event

Public Event GreetingEvent Greeting;

// Method for remotely called by the client

Public void HellometHod (String Greeting)

{

Console.writeline ("Received String {0}", Greeting;

// Pack the string into greetingEventArgs

Greetingeventargs E = New GreetingEventArgs (Greeting);

// trigger 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 HTTP channels.

// This can also be done in the Remoting profile.

ChannelServices.RegisterChannel (New Httpchannel (999));

// Register the server type.

// This can also be done in the Remoting profile.

RemotingServices.RegisterWellkNowntype

"ZAP", // assembly

"Zap.waz", // complete class name

Host / Waz.soap, // URI

WellknownObjectMode.singleton; // Object mode

/ / Complete the operation, waiting for the user to quit

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;

// Put the object by reference to the event to the event to be triggered

Public Class Baz: MarshalByrefObject

{

Public void GreetingHandler (Object Sender, GreetIndargs E)

{

Console.writeline ("GreetingHandler Return: 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 profile.

// Register an HTTP channel

ChannelServices.registerChannel (New Httpchannel (0));

/ / Get SOAP URL Agent

WAZ WAZ = (WAZ) Activator.getObject (

TypeOf (WAZ),

"http:// localhost: 999 / host / waz.soap"

);

/ / Reservation Event: By SOAP

Waz.greeting = new greetingevent (baz.greetinghandler);

For (int i = 0; i <5; i )

{

// Send WAZ through SOAP

Waz.hellomethod ("Bill" "" i);

}

/ / Cancel the predetermined event: through SOAP

Waz.greeting - = new greetingevent (baz.greetinghandler);

}

}

Makefile

Makefile

All: host.exe zap.dll Client.exe

Host.exe: host.cs

CSC /R :system.Runtime.Remoting.dll host.cs

Zap.dll: Zap.cs

CSC / T: library -out: zap.dll zap.cs

Client.exe: Zap.dll Client.cs

CSC /R :System.Runtime.Remoting.dll /R :Zap.dll Client.cs

Start the Host.exe file in a window, then launch the client.exe file in another window. You will see events being raised back to the client.

This is a small example of many .NET Remoting applications. .NET Remoting provides a completely CLR controlled code type system on the network, which is still excellent SOAP server and client because it is fully compliant with the SOAP 1.1 specification.

Use SOAP as ATL development tools

ATL Server Web Services provides simple ways to create and use Web Services in this unit code for C developers. ATL Server is the preferred method for C developers to provide and use Web Services on the Internet, which provides fast, lightweight and highly flexible libraries for web applications that include SOAP web applications.

The reason why ATL Server is called ATL is because it reflects ATL targets that simultaneously pursue high performance and flexibility. For example, you can easily throw an ATL Server HTTP model to write your own schedule, while still get the benefits of the ATL Server Send / Protocol code.

ATL Server Web Services uses a syntax instructions similar to COM to facilitate current ATL developers to learn. This similar syntax similar to the COM allows developers to easily provide objects while providing a COM object and web service. The introduction of attributes greatly simplifies the code, making it easy for non-ATL developers. ATL Server has the ability to interoperate with all other .NET Web Services, which is very convenient for developers who use multiple technologies in an application.

Interface: The new __interface keyword makes the developer easily create a COM object or web service interface.

[

UUID ("D7DAE6FD-AEBB-4579-BD8D-866F74139501"),

Object

]

__interface IWeb_Service_exampleService

{

[ID (1)] HRESULT HELLOWORLD ([In] BSTR BSTRINPUT, [OUT, RETVAL] BSTR * BSTROUTPUT;

}

This is an example of using the ATL Server Defining the Web Service interface. With the C properties, embedded IDL properties, and new __interface keywords, the ATL Server Web Service interface looks very similar to the new attribute COM interface. The Web Service Interface Sample IWEB_SERVICE_EXAMPLESERVICE is only a method HelloWorld. HelloWorld uses BSTR as input and returns BSTR as an output.

Request a handler: The request handler is a C class that is provided by handler mapping and has a method provided by an alternative method map. The handler mapping is just a mapping of the text tag and class name, and the method mapping is a mapping of a class Chinese character label and method.

[

Request_handler (name = "default", sdl = "genweb_service_examplesrvicesdl",

SOAP_HANDLER

Name = "Web_Service_exampleService",

Namespace = "URN: Web_Service_exampleService",

Protocol = "soap"

)

]

Class CWEB_Service_exampleService:

Public IWeb_Service_exampleService

{

PUBLIC:

[SOAP_METHOD]

HRESULT HELLOWORLD (BSTR BSTRINPUT, BSTR * BSTROUTPUT)

{

CCOMBSTR BSTROUT (L "Hello");

BSTROUT = BSTRINPUT;

BSTROUT = L "!";

* bstroutput = BSTROUT.DETACH ();

Return S_OK;

}

}

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 enters IIS, maps the request (URL and its extension) to the appropriate ISAPI DLL. The ISAPI DLL then maps the handler (i.e., the handler specified in the label or query parameter) in the request to the appropriate Application DLL. The Application DLL will then map this handler to the C object. In this model (ATL Server model), the only difference between web applications and web services is the last step. Using Web Services, C objects can decode / encode SOAP (when the compiler parses the soap_handler property, it is inserted into the code to do this). You can understand that this class is inherited from our interface, and we use the [SOAP_METHOD] property indicating that the SOAP request will be processed by the HelloWorld method. This method is to achieve any other C method.

This soap_handler attribute ensures that the WSDL that is automatically generated. Web service users use this description of the service (XML / WSDL) to make sure they can send / receive correct data in the correct format.

Use Web Services via ATL Server

It is a relatively simple operation with Web Services using Web Services. Developers simply use the "Add Web Reference" dialog, point it to the .disco file, point to WSDL, which is the same as using other types of web references. This dialog runs the sproxy.exe utility on the WSDL of the web service in the background (there is another utility for non-book .NET Web Services).

This action will create a Web Service proxy file that contains all C code that requires the requested Web Service. Using the information in WSDL, the agent generator can determine the data to be received by the Web Service and the data it is to be returned to the client. This allows the agent generator to create header files that can be "talk" with the Web Service.

You only need to create an instance of your own Web Service class (as in the generated header file), and use the appropriate method, for example:

CWEB_Service_exampleServiceService MyService;

CCOMBSTR BSTROUT;

CCOMBSTR BSTRIN (L "World");

MyService.helloworld (BStrin, & BSTROUT,);

WPrintf (BSTROUT);

Now you already have a basic ATL Server Web Service and ATL Server Web Service Consumer.

to sum up

The main purpose of this article is to make an overall introduction to the SOAP function in the .NET framework and Visual Studio.NET. Second, on how to create an application using SOAP, give the user some useful guidance.

转载请注明原文地址:https://www.9cbs.com/read-476.html

New Post(0)