Analysis of the framework structure of Microsoft based on Web Computing (reprint)

Source: Internet
Author: User
Tags abstract definition file system http post http request valid web services msmq visual studio
web| Microsoft Microsoft based on Web computing Framework Structure Analysis (reprint)


First, the introduction

With the development of Internet, software system has developed from client server system to server/browser system, but with the deepening of internet-based application and the concept of web-based computing, the new computing model is no longer simply dependent on the browser as the client.

First of all, let's take a look at the history of the computing model, at first, since the PC is not yet popular, and the computer prices are more expensive, we generally use host mode to calculate, that is, the customer is actually through the terminal and a large host to connect, The host allocates a certain amount of CPU time and disk space to the user, and all the user's calculations are actually done on the host. This requires a very high level of host, requiring the operating system on the host to be highly reliable and secure. At this time, the popularity of IBM's mainframe operating system is that, even now, many banks still operate through this mode, because it is easy to centralize management and maintenance, the client is actually just a terminal function, from a certain point of view is the extension of the host screen.

With the development of distributed concept and the enhancement of computer function, the software industry has put forward the client/server computing model, put some non-critical tasks (such as graphical interface display, data display format determination, data processing, etc.) to the client to carry out, so that the relative ease of the burden on the server. However, this model is generally based on the LAN scope (for example, in the 90 's very popular some database based information system is built according to this pattern).

With the development of the Internet and the need of electronic interaction between enterprises, a computing model based on database/web server/browser has emerged, which is actually based on the global network, and the client is displayed to the user in the form of browser. The user delivers the task to the Web server through the HTTP protocol, the Web server passes the result through the HTTP protocol to the client through the interaction with the database and the application server, then the client then displays the result through the browser. The key to this pattern is the security and transactional aspects of data delivery, because HTTP is essentially a stateless connection, so transaction processing becomes very important, and since the entire business is based on the global network architecture, security becomes a concern.

With the complexity of computing tasks on the Internet and the diversification of the business, the need for Web-centric computing is naturally generated. In essence, the complexity of Internet applications makes our current operating system seem powerless, because our current operating system is generally based on stand-alone or LAN systems, and how to extend the operating system to the entire Internet computing context, is a problem that all operating system software manufacturers must consider.

There are many examples of web-based software systems, such as Napster, which allows the sharing of disk content between users, and in a way its basic concept is to build a web-based file system that contains all the participants ' own file systems. This allows the participants to share files, and by entering certain query conditions, we can find the appropriate files on other users ' storage devices and download them (of course, this concept has long existed in the LAN, and now Napster extends the concept to the entire Internet domain).
Second, the Web service Architecture analysis

The advent of this internet-based type of application has led to the need for a new framework for program design, and we need a quick and easy way to write code and interact with other programs on the Internet. Of course, the concept of data and information interaction between computers is not very new, for example, through rpc,dcom and CORBA, you can realize the interaction between processes on different computers. But they all have a fatal drawback: the machines they need to interact with have similar systems, such as MSMQ only with MSMQ, and DCOM clients can only interact with the DCOM server side.

What we really need is a common development framework, which means we can interact with it regardless of what is on the other end of the system. Its essential meaning is that both ends of the operating system can not only be heterogeneous (such as one end can be windows, the other end can be Unix), and the implementation of the language can also be heterogeneous (one end can be implemented with C + +, the other end can be implemented with VB).

If you remember the concept of data set (Marshal) when DCOM interacts, then you can understand what the key point of internet-based heterogeneous system communication is. One is the standard of communication, two processes need to adopt a standard protocol for communication, the other is the data packaging, data should be in a consistent form of packaging and reconciliation package. The internet's most popular transport protocol is HTTP, and all Web browsers communicate with the Web server and get related pages. And the data packaging also needs to adopt a certain standard, the current Cross-platform information coding standard is XML. Because HTTP and XML are industrial standards and are not tied to any platform or vendor, systems built on both of these standards are certainly viable in any environment.

In order to create a Web service, all we have to do is write one. NET service object so that it is called by a remote process as if it could be invoked directly by a local client. It is actually done by labeling it with a certain attribute so that it can be used by Web clients. Through ASP.net, this. NET service object is able to accept requests from the client (transmitted over the HTTP protocol). Other words. NET service object can communicate with any process that uses HTTP and XML standards, and you don't have to consider the architecture of web communications, and the operating system has helped you get it all done.

From the point of view of the service object, communication between a customer and a service object can be expressed in the following form:

1. From the HTTP request from the client, where the parameter may be included in the URL, or it may be contained in a separate XML file
  
2. Asp. NET creates an object based on the specified. asmx file

3. Asp. NET invokes a particular method of the object

4. object returns the result to ASP.net

On the client,. NET provides a proxy class for quick and easy interaction with a server-provided Web service, a description of the Web service through a development tool, and then a proxy class that contains functional functions, noting that we can use any type of language to develop the client, When a client invokes one of these functions, the proxy generates an HTTP request and sends it to the server, and when the server response returns, the proxy can parse the result and return it to the client that called the function. This ensures that the client can interact seamlessly with the Web server through HTTP and XML.

From the client's perspective, communication between a customer and a service object can be expressed in the following form:

1. At run time, the client produces a proxy object

2. A method in the client invocation proxy

3. Proxy converts the call to HTTP and XML forms and sends it over the Internet to the server side

4. The proxy obtains the result in XML form through the HTTP protocol, and converts the corresponding result value to the customer

Third, the preparation of Web services

Here we can write a simplest web service to illustrate the use of this new technology, which provides the time of the current server as a string (can be precise or imprecise to seconds). The program starts with the standard tag "<%@...%>", within which WebService tells ASP.net that the code for the page appears as a Web service. Language told ASP that the language used to compile this page is VB, and then ASP.net will use Visual Basic.NET to compile the code. The Class property tells ASP.net that the current class object's name is Timeservice.

The specific code is as follows:

<%@ WebService language= "VB" class= "Timeservice"%>

' Introducing namespaces ' requires web Service
Imports System
Imports System.Web.Services
' Create a new class that must inherit the base class provided by the system WebService
Public Class timeservice:inherits WebService
' Create the function we need in the class and mark it as WebMethods
Public Function <webmethod () > GetTime (Showseconds as Boolean) as String
' Complete the function: Discover the current time, format it, and return it as a string
Dim DT as DateTime
If (showseconds = TRUE) Then
GetTime = dt. Now.tolongtimestring
Else
GetTime = dt. Now.toshorttimestring
Endif
End Function
End Class

To allow developers to use Web services to develop client applications, it is necessary to provide them with certain information when designing and developing them. For example, a Web service client needs to know the method that the Web service exposes and the associated parameters, and the protocols it supports, similar to the concept of a type library carried by a standard COM. But the type library is private to COM, and the method we provide should be independent of the specific architecture, so we need to write a generic description of the service method. Asp. NET provides a descriptive service when compiling a Web service, ASP. NET provides a list of files that describe the protocols that the service supports, the methods and parameters it provides, and so on. This file is encoded in XML and is described using a language called SDL (Service descriptor Language). Can you pass Http://WebServer/specifiedDirectory/TimeService.asmx? SDL in this form to get the SDL language.

When we use VB or VC to write COM components, we generally need to write a type library to describe the functionality that the COM component can provide. For ASP.net, it can automatically generate an SDL file, or you can write an SDL file and then generate a service template file from the System tools.

A typical SDL file contains the following:

!--a standard XML header that describes version information and other relevant information-->
<?xml version= "1.0"? > >
The!--element servicedescription is the root node of the file, which is the description of the Web service-->
The!--value Timeservice represents the name of the service-->
<servicedescription name= "Timeservice"
The!--element servicedescription includes two child elements, one is the protocol description and the other is the document schema description-->
The <!-protocol description is used to tell the client developer the protocol supported by my Web service and to tell him the encoding format of the request and response data-->
<!-Here we describe the operation of HTTP GET, there are generally three methods of HTTP Get,http post and SOAP three kinds of methods-->
<service>
<requestresponse name= "GetTime" href= "Http://WebServer/specifiedDirectory/TimeService.asmx/GetTime"
<request>
<param name= "Showseconds"/>
</request>
<response>
<mimexml ref= "s1:string"/>
</response>
</requestResponse>
</service>

<!-Here you can describe other protocols, such as HttpGet and soap.
The <!-schema represents an abstract definition of a service that has nothing to do with what protocol is used to communicate with it.
<!-It actually contains the name of the function that the service contains, the representation of the parameter and the return value-->

<schema>
<element name= "GetTime"
<complexType>
<element name= "Showseconds" Type= "boolean"
</complexType>
</element>
<element name= "Gettimeresult"
<complexType>
<element name= "Result" type= "string" nullable= "true"/>
</complexType>
</element>
</schema>
</serviceDescription>

Four, the Web service client's writing

Now let's take a look at how to write the client code. We know that asp.net is actually listening on three kinds of packets, including HTTP Get,http post and soap.

1. Methods of using HTTP GET:

The basic format is as follows:

Http://webserver/specifiedDirectory/timeservice.asmx/GetTime?ShowSeconds=TRUE

2. Using the HTTP POST method:

It is actually sending the request through the form format of HTML, whose main code is as follows

<form method= "POST" action= "Http://webserver/specifiedDirectory/timeservice.asmx/GetTime"
<p> Show seconds? </p>
<blockquote>
<p> <input type= "RADIO" name= "Showseconds" value= "True" checked>
True
<input type= "RADIO" name= "Showseconds" value= "False" >false <br>
</p> </blockquote>
<input type= "Submit" value= "Submit Form"
<input type= "reset" value= "Reset Form" "
</form>

3. The method of using soap:

The server accepts packets sent over HTTP POST requests, and the packets are saved in a SOAP packet format. Note that the SOAP package here is actually an XML document that contains the name of the function and the associated parameters, and when the SOAP packet reaches the server, APS. NET recognizes the SOAP package, extracts the methods and corresponding parameters contained in the package, creates the object, and then executes a call to the method. and returns the result as an XML document to the client. The key here is to synthesize a valid SOAP packet, and to extract valid information from the returned XML document.

Here we can use the following VB code to implement the SOAP based client.

Private Const quotetemplate =
"<?xml version=" "1.0" "? > >
<envelope xmlns = "" http://schemas.xmlsoap.org/soap/envelope/"" "
<Body>
<gettime xmlns:xsi= "" Http://www.w3.org/1999/XMLSchema-instance "" xmlns= "" Http://tempuri.org/main.xsd ""
<ShowSeconds> true </ShowSeconds>
</GetTime>
</Body>
</Envelope> the

Private Sub Btngettime_click ()

' Create a DOM object
Dim parser as New DOMDocument
' Load XML document template
Parser.loadxml (Quotetemplate)
' Set the value of the parameter Showseconds
If (check1.value = 0) Then
Parser.selectsinglenode ("/envelope/body/gettime/showseconds"). Text = "false"
Else
Parser.selectsinglenode ("/envelope/body/gettime/showseconds"). Text = "true"
End If

' Put the contents of the XML document in the edit control txtsend
Txtsent.text = Parser.xml
' Perform HTPP post operations with Microsoft Internet Transfer controls
Inet1.execute Txturl.text, "POST", Parser.xml, "content-type:text/xml" + vbcr + vblf + "Soapaction:http://tempuri.org/ge Ttime "
 
End Sub

' Control INETL1 message trigger handling

Private Sub inet1_statechanged (ByVal State as Integer)

If (state =) Then

' Read data returned from the server side
Dim Bar as String
Bar = Inet1.getchunk (4096)
' Store the data returned from the server side to the edit control txtreceived
Txtreceived.text = Bar
' Store the returned string in an XML document
Dim Docin as New DOMDocument
Docin.loadxml (BAR)
' Using the DOM model to get the value of the element price
Dim Price as IXMLDOMNode
Set Price = Docin.selectsinglenode ("Soap:envelope/soap:body/getstockquoteresponse/price")
If (price are nothing) Then
Txtprice = "(Error)"
Else
Txtprice = Price.text
End If
End If
End Sub

4. Operate through intelligent SOAP proxies

This approach requires the use of visual The Studio.NET development tool, which reads the description of the Web service through the SDL file and generates a proxy (note that the proxy can be automatically generated using a certain tool) that inherits the base class Web.Services.Protocols.SoapClientProtoco L The proxy class contains a property called Path, which indicates the URL address of the server, which contains a default value from the SDL file, the client uses method invoke to activate the method in the proxy (e.g. a), the method (a), and then creates a SOAP package, The package contains the name and parameters of the method and then sends it to the server via the HTTP protocol. When the SOAP response packet is returned from the server, the base class parses the returned value and returns it to the proxy, which is returned to the customer by proxy. You can then use the specific language to manipulate the proxy, which currently supports visual baisc.net,c# and JavaScript, but does not support C + +.

Here is the code written with vb.net to interact with the proxy:

Public Class Form1 Inherits System.WinForms.Form
' When you click on the button gettimesynch processing (synchronous processing)
Protected Sub Btngettimesynch_click (ByVal sender as System.Object, ByVal e as System.EventArgs)
' Creates an object instance of a new proxy class
Dim Thistimeserviceproxy as New timeservice ()
' Sets the value of the property path specified by the user
Thistimeserviceproxy.path = TextBox2.Text
' Actually call the method and return the result to the text box
' CheckBox1 value ' represents the parameter value of the method gettime
TextBox1.Text = Thistimeserviceproxy.gettime (checkbox1.checked)
End Sub

Dim Asynctimeserviceproxy as Timeservice
Dim AsyncResult as IAsyncResult
' When you click on the button Gettimeasynch processing (asynchronous processing)
Protected Sub Btn_begingettimeasync_click (ByVal sender as System.Object, ByVal e as System.EventArgs)

Asynctimeserviceproxy = New Timeservice

AsyncResult = Asynctimeserviceproxy.begingettime (checkbox1.checked, nothing, nothing)
End Sub

' Check if the current operation is over
Protected Sub Btnpollforcomplete_click (ByVal sender as System.Object, ByVal e as System.EventArgs)
If (asyncresult.iscompleted) Then
MsgBox ("Complete")
Else
MsgBox ("Not Complete")
End If
End Sub

' Gets the result of using the asynchronous method call

Protected Sub Btnendgettimeasync_click (ByVal sender as System.Object, ByVal e as System.EventArgs)
TextBox1.Text = Asynctimeserviceproxy.endgettime (asyncresult)
Asynctimeserviceproxy = Nothing

End Sub
End Class

We know that an internet-based computing environment is much more complex than a desktop based environment, and it takes a lot longer to interact, such as a call to a simplest Web service that can take 5-10 seconds or more, and at this point you can't expect the user to be dumb enough to wait there all the time. In other words, because the desktop interaction time is very short, we can invoke a method called the component in a synchronous way, but in internet-based computing, we must adopt the method of asynchronous invocation.

The above vb.net code also demonstrates the method of asynchronous invocation, in fact the proxy itself contains a method called Beginmethodname, which in our case is begingettime, when this method is invoked, the program returns immediately, Then you can do other things you want to do, and when you need to see the results, you need to call the method Endmethodname and get the results. Of course, if you call method Endmethodname before the result returns, the program blocks until the result is obtained from the server. To prevent the entire interface from blocking, you can invoke the Endmethodname method in a worker thread when you actually implement it.

V. Conclusion

In fact, almost all programmers want to write programs that interact on the Internet, regardless of what their platform is running on. and by using HTTP and XML technology, we are basically able to achieve this function. As long as the client packages the data in XML and transmits it as HTTP, the server can handle it, and on the server side, it creates an SDL file to describe the methods and parameters that the service object can provide so that the client can invoke the service object correctly. At the same time, a proxy builder provides a set of functions to reach the Web service, making it easier for the client program to write.

It should be explained that Microsoft is about to launch the visual Studio.NET This development tool provides an integrated environment for developing Web services, and the architecture of this Web service also provides a level of security for Web applications that enable developers to quickly and efficiently build internet-based applications.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.