分享
 
 
 

The System.Web.Services Namespace

王朝asp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

The System.Web.Services Namespace

XML Web Services provide one of the newest and most exciting technologies

for development, as far as we're concerned. Although the .NET platform, and

Visual Studio .NET in particular, makes it easy to get started creating XML

Web Services, Web Services have been available for some time on the

Microsoft platform, thanks to the SOAP Toolkit. (Stop by

http://msdn.microsoft.com/xml for more information on the SOAP Toolkit and

how it can enable you to consume Web Services in non-.NET client

applications.)

XML Web Services make it possible to execute method calls provided by

objects via the Web. Distributed components have been available for years,

in the form of ActiveX components accessed via DCOM, but Web Services make

components available over HTTP using SOAP as the underlying messaging

protocol. DCOM is a binary standard that doesn't transmit well through

firewalls or proxy servers. In addition, DCOM is only supported on

platforms running COM, which has basically limited COM/DCOM to Windows

platforms.

With Web Services, however, the landscape has changed. The call and

response to a Web Service are in XML format and are generally transported

over HTTP. This means that the component can be called using simple text

and by any client on any platform. The result comes back in XML format,

meaning that any client that understands XML can consume the results.

Finally, you can code your components using your favorite Microsoft tools

and allow those components to be used by people running on Unix or an AS/400

梠r any other platform that can make HTTP calls and consume XML. Realize

that you can consume a Web Service from a Windows application, a Web

application, or any other client you can imagine, including the growing set

of wireless devices, such as PDAs and Web-enabled phones. This opens up a

new world of interoperability and means you can distribute your application

on servers around the world and tie them together using just HTTP.

Creating XML Web Services is fairly straightforward, as you will see in the

next section. In Part IV of this book, you will learn how to create more

fully-functional Web Services. In this chapter, you will just learn to

create a simple Web Service, and you'll see a simple way to access that Web

Service.

NOTE

We use the term Web Services to refer to the technology that allows you to

communicate with objects using specially formatted XML streams, usually

over HTTP. The term we ought to be using is XML Web Services, because there

are other emerging technologies that provide services over the Web. This

terminology becomes distracting, however, and we'll simply refer to it as

Web Services throughout the book.

A System.Web.Services Example

In order to create a new Web Service, start by creating a new project in

Visual Studio .NET and selecting the ASP.NET Web Service template. Name the

new project TestWebService (accepting the default location,

http://localhost . Select Service1.asmx in the Solution Explorer window,

and select the View, Code menu item to display the associated class. As you

can see, Visual Studio .NET has created the shell of the service for you,

including commented lines of code showing how to expose public Web methods.

Add the following procedure to the sample class:

<WebMethod()> _

Public Function Hello( _

ByVal Name As String) As String

Return "Hello, " & Name

End Function

The one public function here, Hello, simply returns a greeting to the name

you pass in as a parameter.

NOTE

What's the <WebMethod()> text you see in the procedure declaration for?

This procedure attribute indicates to the compiler that the procedure

should be serialized using the SOAP serializer, for use as part of a Web

Service. Without this, you'd simply be creating a public method of a class,

just like normal.

Choose the Build, Build Solution menu item to rebuild the project. (This

step creates a DLL and places it in a location on your Web server within

the project folder.)

It's simple to test the Web Service: Open your Web browser and type in the

following URL, replacing the server name and project name if necessary:

http://localhost/TestWebService/Service1.asmx/

Hello?Name=Paul

The result that will appear in your browser is the XML response from the

Web Service. It will look like this:

<?xml version="1.0" encoding="utf-8" ?>

<string xmlns="http://tempuri.org/ >Hello, Paul</string>

If you're not excited yet, think about this: You called a method in a

component over standard HTTP and retrieved the result, all over the

Internet! (Okay, you're on your local machine, but it could just as easily

have been over the Internet!) This is a very powerful technique, and it

opens up a whole new way of programming and creating distributed

applications.

Normally, you'd call this Web Service from a client application. In Visual

Studio .NET, you can simply add a Web reference to your Web Service. This

is just like adding a reference to a COM component in previous versions of

Visual Studio. After adding the Web reference, you refer to the Web Service

as you would any other component.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有