ASP.NET相关的外文文献

10000个字符以上
2025-06-24 00:43:35
推荐回答(1个)
回答1:

我的毕业论文有.但字数太多.发不上来.
Web Services
A great place to begin an exploration of Web services is to define precisely what a Web service is. A Web service is an application that:
• Runs on a Web server
• Exposes Web methods to interested callers
• Listens for HTTP requests representing commands to invoke Web methods
• Executes Web methods and returns the results
Most Web services expect their Web methods to be invoked using HTTP requests containing SOAP messages. SOAP is an XML-based vocabulary for performing remote procedure calls using HTTP and other protocols. You can read all about it at http://www.w3.org/TR/SOAP. Suppose you write a Web service that publishes Web methods named Add and Subtract that callers can use to add and subtract simple integers. If the service’s URL is www.wintellect.com/calc.asmx, here’s how a client would invoke the Add method by transmitting a SOAP envelope in an HTTP request. This example adds 2 and 2:
POST /calc.asmx HTTP/1.1
Host: www.wintellect.com
Content-Type: text/xml; charset=utf-8
Content-Length: 338
SOAPAction: "http://tempuri.org/Add"


xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">


2
2



And here’s how the Web service would respond:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 353


xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">


4



The Web service’s job is to parse the SOAP envelope containing the inputs, add 2 and 2, formulate a SOAP envelope containing the sum of 2 and 2, and return it to the client in the body of the HTTP response. This, at the most elemental level, is what Web services are all about.
Web services written with the .NET Framework also allow their Web methods to be invoked using ordinary HTTP GET and POST commands. The following GET command adds 2 and 2 by invoking the Web service’s Add method:
GET /calc.asmx/Add?a=2&b=2 HTTP/1.1
Host: www.wintellect.com
The Web service responds as follows:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 80


4
Here’s a POST command that adds 2 and 2:
POST /calc.asmx/Add HTTP/1.1
Host: www.wintellect.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 7

a=2&b=2
And here’s the Web service’s response:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 80


4
As you can imagine, the hard part of writing a Web service is parsing HTTP requests and generating HTTP responses. But as you’ll see in the next section and throughout the remainder of this chapter, the .NET Framework insulates developers from the low-level details of HTTP, SOAP, and XML and provides a high-level framework for writing Web services and Web service clients alike.
There are many ways to write Web services. You can write Web services by hand. You can use SOAP toolkits from Microsoft, IBM, and other companies. And you can use the .NET Framework. Because this book is about Microsoft .NET, this chapter is about the latter. Writing Web services with the .NET Framework offers two advantages over all the other methods:
• The .NET Framework makes writing Web services extremely easy.
• Web services written with the .NET Framework are managed applications, meaning you shouldn’t have to worry about memory leaks, stray pointers, and other maladies that bedevil programmers and cost more than their fair share of development time.
What does it take to write a Web service using the .NET Framework? I’m glad you asked, because that’s what the next section is about.
Your First Web Service
The ASMX file shown in Figure 11-1 is a complete Web service. It implements two Web methods: Add and Subtract. Both take two integers as input and return an integer as well. Deploying the Web service is as simple as copying it to a directory on your Web server that is URL-addressable. If you put Calc.asmx in wwwroot, the Web service’s local URL is http://localhost/calc.asmx.
Calc.asmx demonstrates several important principles of Web service programming using the .NET Framework:
• Web services are implemented in ASMX files. ASMX is a special file name extension registered to ASP.NET (specifically, to an ASP.NET HTTP handler) in Machine.config.
• ASMX files begin with @ WebService directives. At a minimum, the directive must contain a Class attribute identifying the class that makes up the Web service.
• Web service classes can be attributed with optional WebService attributes. The one in this example assigns the Web service a name and a description that show up in the HTML page generated when a user calls up Calc.asmx in his or her browser. The WebService attribute also supports a Namespace parameter that can be used to change the name of the XML namespace that scopes the Web service’s members.
• Web methods are declared by tagging public methods in the Web service class with WebMethod attributes. You can build helper methods into a Web service—methods that are used internally by Web methods but that are not exposed as Web methods themselves—by omitting the attribute. The WebMethod attributes in Figure 11-1 also assign descriptive text to their Web methods. You’ll learn more about Description and other WebMethod parameters in the section entitled “The WebMethod Attribute.”
• HTTP, XML, and SOAP are hidden under the hood. You don’t have to deal with raw XML data or SOAP messages because the .NET Framework deals with them for you.