查看完整版本: .NET框架和VS.NET中的SOAP

格格巫 2008-8-7 10:59

.NET框架和VS.NET中的SOAP

<STRONG><FONT color=#ac0000>简介<BR><BR></FONT></STRONG>  [url=http://whatis.ctocio.com.cn/searchwhatis/251/5948751.shtml]Microsoft[/url]? .NET 框架和 Microsoft? Visual Studio.NET 利用 [url=http://whatis.ctocio.com.cn/searchwhatis/203/5949203.shtml]XML[/url] 和 [url=http://whatis.ctocio.com.cn/searchwhatis/437/7372437.shtml]SOAP[/url] 技术,使开发人员能够创建广泛的解决方案。SOAP 是一个简单、轻便、并在业界获得广泛支持的协议,适用于各种各样的应用,它与 .NET 框架的结合简单而合乎自然。 <BR><BR>  从底层开始,SOAP 的设计目标就是使之成为一种非常简单的协议,能够以各种不同的方式满足各种不同的需求。除了 Microsoft,已有许多公司实际应用 SOAP,例如 [url=http://whatis.ctocio.com.cn/searchwhatis/199/5948199.shtml]IBM[/url]、Develop Mentor 和 Userland。<BR><BR>  在使用 SOAP 的体系中,有若干种关键技术。在创建基于 SOAP 的解决方案时,每种技术都会解决开发人员的一些共同问题。这些技术分别属于 .NET Remoting、[url=http://whatis.ctocio.com.cn/searchwhatis/451/6092451.shtml]ASP.NET[/url] <A href="http://dev.chinaitpower.com/dotnet/webservice/" target=_blank><FONT color=#0000ff>Web Service</FONT></A>s 和 ATL Web Services,它们具有许多共同的技术特点:<BR><BR>   用于消息生成和使用的 XML。<BR><BR>   符合 SOAP 1.1 规范,包括第 5 节 SOAP 编码,这使 SOAP 应用之间具有很好的互操作性。<BR><BR>   XML 保真性(非第 5 节 SOAP 编码),用于完全断开的模型。<BR><BR>   [url=http://whatis.ctocio.com.cn/searchwhatis/205/7421705.shtml]WSDL[/url](XML 方案的一种形式),用于提供说明。<BR><BR>   可用无状态编程模型扩展系统。<BR><BR>  使用 Visual Studio.NET 的良好开发环境。 <BR><BR>  ASP.NET Web Services 和 .NET Remoting 还共享下列技术:<BR><BR>   XCOPY 系统部署。<BR><BR>   System.Net,进行[url=http://networking.ctocio.com.cn/]网络[/url]通讯时,无论在[url=http://server.ctocio.com.cn/]服务器[/url]还是客户端它都运行良好。<BR><BR>   公共语言运行时可在受控代码和[url=http://whatis.ctocio.com.cn/searchwhatis/146/7352146.shtml]线程[/url]缓冲池中重用。<BR><BR>   提供强大的 SOAP 支持,例如 SOAP 头和单向消息等特性。<BR><BR>   能够与 [url=http://whatis.ctocio.com.cn/searchwhatis/439/5946939.shtml]C#[/url]、Visual Basic.NET 或任何符合 CLS 规范的语言(如 Cobol、[url=http://whatis.ctocio.com.cn/searchwhatis/388/6026388.shtml]Python[/url]、 ComponentPascal 等等)配合使用来编写应用程序。 <BR><BR>  除了以上列出的共同特点和技术以外,ASP.NET Web Services、.NET Remoting 和 ATL Web Services 还分别为开发人员提供了许多特有的功能,下面这些内容有助于开发人员在生成应用程序时把握正确的方向。<BR><BR><BR><BR>  <B>如果您要生成 .ASP 应用程序,ASP.NET <A href="http://dev.chinaitpower.com/dotnet/webservice/" target=_blank><FONT color=#0000ff>Web Service</FONT></A>s:</B><BR><BR>   允许与 ASP.NET HTTP 运行时紧密集成。<BR><BR>   鼓励开发人员着重于运用 XSD 数据类型来提供应用程序。<BR><BR>   在 Visual Studio.NET 中提供强大的设计支持。 <BR><BR>  <B>如果您要生成 MTS/[url=http://whatis.ctocio.com.cn/searchwhatis/308/5947308.shtml]COM+[/url] 应用程序,.NET Remoting:</B><BR><BR>   提供全面的受控代码类型系统的网络保真性。<BR><BR>   提供在网络上通过引用来传递对象的功能,并且可返回到特定[url=http://whatis.ctocio.com.cn/searchwhatis/292/7333792.shtml]进程[/url]中的特定对象。<BR><BR>   提供二进制通讯能力。 <BR><BR>  <B>如果您要生成 ATL/[url=http://whatis.ctocio.com.cn/searchwhatis/441/5946941.shtml]C++[/url] 应用程序,ATL Server:</B><BR><BR>   提供灵活并且可控的本机 (C++) 解决方案。<BR><BR>   建立于 ATL Server [url=http://whatis.ctocio.com.cn/searchwhatis/229/6025729.shtml]ISAPI[/url] Web 应用体系机构之上(利用线程缓冲池、缓存,等等)。 <BR><BR><B>  将 SOAP 用作 Web 开发工具</B><BR><BR>  ASP.NET Web Services 提供了 [url=http://whatis.ctocio.com.cn/searchwhatis/471/6028471.shtml]RAD[/url] 方式,以供快速创建和使用 Web 服务。这些服务宽松地组合在一起,并可与 ASP.NET 高度集成。ASP.NET Web Services 是 Web 开发人员在 [url=http://whatis.ctocio.com.cn/searchwhatis/127/6025627.shtml]Internet[/url] 上提供 Web 服务的首选方法,它的目标是提供快速、简便、性能优越的 SOAP 服务。<BR><BR>  ASP.NET Web Services 可以和 ASP.NET HTTP 引擎深入集成,这使得熟悉 Microsoft Web 开发技术的开发人员能够方便地生成和使用基于 SOAP 的 Web 服务。<BR><BR>  ASP.NET 以 .asmx 文件提供对 Web Services 的支持。.asmx 文件是与 .aspx 文件相似的文本文件。这些文件可以是包含 .aspx 文件的 ASP.NET 应用程序的一部分。它们可以使用 [url=http://whatis.ctocio.com.cn/searchwhatis/124/5949124.shtml]URI[/url] 寻址方式,这和 .aspx 文件相同。<BR><BR>  以下是一个非常简单的 .asmx 文件示例:<BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD><%@ WebService Language="C#" Class="HelloWorld" %><BR><BR> using System;<BR> using System.Web.Services;<BR><BR> public [url=http://whatis.ctocio.com.cn/searchwhatis/213/5947213.shtml]class[/url] HelloWorld : WebService {<BR><BR> [WebMethod] public String SayHelloWorld() {<BR> return "[url=http://whatis.ctocio.com.cn/searchwhatis/62/5948062.shtml]Hello World[/url]";<BR>}<BR><BR>}</TD></TR></TBODY></TABLE><BR>  这个文件以 ASP.NET 指示的 Web Service 开始,并将语言设置为 C#(也可以将语言设置为 Microsoft Visual Basic?、C 或大约 30 种第三方语言中的任何一种)。然后,它将导入名称空间 System.Web.Services。这个名称空间是必要的,您必须在文件中包括它。下一步,声明 HelloWorld 类。这个类从基类 WebService 导出。最后,任何要作为服务的一部分来访问的方法在它们的签名之前将具有自定义属性 [WebMethod],在 Visual Basic 中则为“<WEBMETHOD()>”。<BR><BR>  要使这个服务生效,可以将文件命名为 HelloWorld.asmx,然后将它放在虚拟目录 [url=http://whatis.ctocio.com.cn/searchwhatis/228/5946728.shtml]Bar[/url] 中的服务器 Foo 上。使用几乎任何兼容 HTML 3.2 或更高版本的浏览器,都可以输入 [url=http://whatis.ctocio.com.cn/searchwhatis/125/5949125.shtml]URL[/url] http://Foo/Bar/HelloWorld.asmx 来显示这个 Web Service 的公用方法(标有 WebMethod 属性),以及那些可用来调用这些方法的协议,例如 SOAP 或 HTTP GET。如果在 [url=http://whatis.ctocio.com.cn/searchwhatis/139/6025639.shtml]Internet Explorer[/url] 地址栏中输入 http://Foo/Bar/HelloWorld.asmx?[url=http://whatis.ctocio.com.cn/searchwhatis/435/5948935.shtml]SDL[/url],基于服务说明语言 (WSDL) 语法,将产生与 XML 文件相同的信息。这个 WSDL 文件由访问服务的客户使用,并且非常重要。<BR><BR><BR>  <B><FONT color=#ac000>访问 Web Serivces</FONT></B><BR><BR>  除了使开发人员能够创建 <A href="http://dev.chinaitpower.com/dotnet/webservice/" target=_blank><FONT color=#0000ff>Web Service</FONT></A>s 的技术之外,Microsoft .NET 框架还提供了一套用来“使用”(即以客户端身份访问)Web Services 的成熟工具与代码。因为 Web Services 基于简单对象访问协议 (SOAP) 和 HTTP 等开放协议,所以这种客户端技术也可以用于使用非 ASP.NET Web Services。<BR><BR>  [url=http://whatis.ctocio.com.cn/searchwhatis/433/5948933.shtml]SDK[/url] 中有一种称为 WebServiceUtil.exe 的工具(在 VS [url=http://whatis.ctocio.com.cn/searchwhatis/243/7422243.shtml]IDE[/url] 中使用“Add Web Reference...”选项时自动生效)。这个程序可用于下载 Web Service 的 WSDL 说明,然后创建表示这个服务的地址的代理类。例如,您可以输入:<BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>WebServiceUtil /c:[url=http://whatis.ctocio.com.cn/searchwhatis/351/6026351.shtml]proxy[/url] /pa:http://someDomain.[url=http://whatis.ctocio.com.cn/searchwhatis/307/5947307.shtml]com[/url]/someFolder/HelloWorld.asmx?SDL</TD></TR></TBODY></TABLE><BR>  然后,系统将创建称为 HelloWorld.cs 的代理类。<BR><BR>  这个类与前面创建的类看起来非常相似。它包括称为 SayHelloWorld 的方法,该方法返回字符串。将这个代理类编译到应用程序中,然后调用其方法,结果是代理类在 HTTP 上打包 SOAP 请求,并接收 SOAP 编码的回应,然后封送为一个字符串。<BR><BR>  从客户端来看,代码非常简单:<BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>Dim myHelloWorld As New HelloWorld()<BR>Dim sReturn As String = myHelloWorld.SayHelloWorld()</TD></TR></TBODY></TABLE><BR>  返回值将是“Hello World”。<BR><BR>  <B><FONT color=#ac000>将 SOAP 用作组件开发工具</FONT></B><BR><BR>  创建分布式应用程序时,如果需要高度控制性并要求能够选择系统耦合程度,那么可以使用 Microsoft .NET Remoting。<BR><BR>  Microsoft .NET Remoting 还提供了与公共语言运行时的深入集成,并且为开发人员提供了全面的跨连接类型系统保真性。这包括构造函数、委托、重载方法、通过值和引用传递对象、类的层次结构、接口、方法、属性、字段,以及通过可插入[url=http://whatis.ctocio.com.cn/searchwhatis/402/7420402.shtml]通道[/url]、分布式标识、激活、租用生存期和 CallContext(独立于参数的 SOAP 头中的流对象)在连接上的应用程序 (Web Services) 之间进行 Marshal by Value(制作副本)以及 Marshal by Ref(传递 ObjRef)。<BR><BR>  使用 .NET Remoting,开发人员可以从任何进程提供 Remoting 终结点,包括控制台应用、[url=http://whatis.ctocio.com.cn/searchwhatis/260/6093260.shtml]GUI[/url] 应用、[url=http://whatis.ctocio.com.cn/searchwhatis/485/6093485.shtml]NT[/url] Service 和 [url=http://whatis.ctocio.com.cn/searchwhatis/452/6025452.shtml]IIS[/url]。在任何使用有效加载编码(在产品中提供了可插入序列化格式化程序以及 SOAP 和二进制格式化程序)通过可插入通道进行的任何传输过程中都会出现这种情况。SOAP=HTTP+XML,同时完全支持 HTTP 和 SMTP 上的 SOAP 1.1,这十分令人满意。<BR><BR>  我们可以获得 WSDL 支持来说明 Web Service 并保证运行时类型系统的完全保真性。.NET Remoting 提供了 .NET SDK 的 Soapsuds 工具,可以从元数据生成受控类和 COM 对象的服务说明。Soapsuds 工具也使用服务说明并生成元数据和代理。开发人员可以使用密集侦听模型,将自己的操作作为应用程序入站和出站消息流插入。想更为深入的开发人员则可以采用使用套接字的二进制编码 [url=http://whatis.ctocio.com.cn/searchwhatis/96/6092596.shtml]TCP[/url] 通道。<BR><BR>  .NET Remoting 使受控组件、本机 COM/COM+ 组件以及接受服务的组件(使用 COM+ 服务的受控组件)远程化。SOAP、二进制以及任何一种可插入通道和格式上都可能出现这些情况。<BR><BR><BR>  <B><FONT color=#ac000>样例:SOAP 受控代码事件</FONT></B> <BR><BR>  下列代码演示如何在两个应用程序之间引发受控代码事件。客户端有一个本地对象,注册为接收远程对象的事件通知。客户端呼叫服务器对象时,就引发事件,产生对客户端本地对象的回叫。<BR><BR>  服务器端<BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>[url=http://whatis.ctocio.com.cn/searchwhatis/234/5949234.shtml]zap[/url].cs<BR>using System;<BR><BR>[url=http://whatis.ctocio.com.cn/searchwhatis/272/6025772.shtml]namespace[/url] Zap<BR>{<BR>// 定义事件参数<BR>public class GreetingEventArgs : EventArgs<BR>{<BR>public GreetingEventArgs([url=http://whatis.ctocio.com.cn/searchwhatis/400/6026400.shtml]string[/url] greeting)<BR>{<BR>this.greeting = greeting;<BR>}<BR><BR>public string greeting;<BR>}<BR><BR>// 定义事件<BR>public delegate void GreetingEvent([url=http://whatis.ctocio.com.cn/searchwhatis/330/6025830.shtml]object[/url] sender, <BR>GreetingEventArgs e);<BR><BR>// 定义服务<BR>public class Waz : MarshalByRefObject<BR>{<BR>// 客户端将预定和取消预定此事件<BR>public event GreetingEvent Greeting;<BR><BR>// 由客户端远程调用的方法<BR>public void HelloMethod(string greeting)<BR>{<BR>Console.WriteLine("Received String {0}", greeting);<BR><BR>// 将字符串打包到 GreetingEventArgs 中<BR>GreetingEventArgs e = new GreetingEventArgs(greeting);<BR><BR>// 引发事件<BR>if (Greeting != null)<BR>{<BR>Greeting(this, e);<BR>}<BR>}<BR>}<BR>}<BR><BR>[url=http://whatis.ctocio.com.cn/searchwhatis/128/5948128.shtml]host[/url].cs<BR><BR>using System;<BR>using System.IO;<BR>using System.Runtime.Remoting;<BR>using System.Runtime.Remoting.Channels.HTTP;<BR><BR>public class Host<BR>{<BR>public static void Main(string[] args)<BR>{<BR>// 手动加载 http 通道。<BR>// 这也可以在 Remoting 配置文件中完成。<BR>ChannelServices.RegisterChannel(new HTTPChannel(999));<BR><BR>// 注册服务器类型。<BR>// 这也可以在 Remoting 配置文件中完成。<BR>RemotingServices.RegisterWellKnownType(<BR>"Zap", // 程序集<BR>"Zap.Waz", // 完整的类名<BR>"host/Waz.soap", // URI<BR>WellKnownObjectMode.Singleton); // 对象模式<BR><BR>// 完成操作,等候用户退出<BR>Console.WriteLine("主机已经准备好处理远程消息。");<BR>Console.WriteLine("请按 ENTER 键退出");<BR>String keyState = Console.ReadLine();<BR>}<BR>}<BR><BR>客户端<BR>[url=http://whatis.ctocio.com.cn/searchwhatis/233/5947233.shtml]client[/url].cs<BR><BR>using System;<BR>using System.Runtime.Remoting;<BR>using System.Runtime.Remoting.Channels.HTTP;<BR><BR>using Zap;<BR><BR>// 将对象按引用本地封送到要引发的事件<BR>public class Baz : MarshalByRefObject<BR>{<BR>public void GreetingHandler(object sender, GreetingEventArgs e)<BR>{<BR>Console.WriteLine("GreetingHandler 回叫: 问候: {0}\n", <BR>e.greeting);<BR>}<BR>}<BR><BR>public class Client<BR>{<BR>public static void Main(String[] args)<BR>{<BR>Baz baz = new Baz();<BR><BR>// 这也可以在 Remoting 配置文件中完成。<BR><BR>// 注册 HTTP 通道<BR>ChannelServices.RegisterChannel(new HTTPChannel(0));<BR><BR>// 获取 SOAP URL 代理<BR>Waz waz = (Waz)Activator.GetObject(<BR>typeof(Waz),<BR>"http://localhost:999/host/Waz.soap"<BR>);<BR><BR><BR>// 预定事件: 通过 SOAP 进行<BR>waz.Greeting += new GreetingEvent(baz.GreetingHandler);<BR><BR>for ([url=http://whatis.ctocio.com.cn/searchwhatis/69/6025569.shtml]int[/url] i = 0; i &lt; 5; i++)<BR>{<BR>// 通过 SOAP 向 waz 发送<BR>waz.HelloMethod("Bill" + " " + i);<BR>}<BR><BR>// 取消预定事件: 通过 SOAP 进行<BR>waz.Greeting -= new GreetingEvent(baz.GreetingHandler);<BR>}<BR>}<BR></TD></TR></TBODY></TABLE><BR>  <B>Makefile</B><BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>makefile<BR><BR>all: Host.exe Zap.dll Client.exe<BR><BR>Host.exe: Host.cs<BR>csc /r:System.Runtime.Remoting.dll Host.cs<BR><BR>Zap.dll: Zap.cs<BR>csc /t:library -out:Zap.dll Zap.cs<BR><BR>Client.exe: Zap.dll Client.cs<BR>csc /r:System.Runtime.Remoting.dll /r:Zap.dll Client.cs</TD></TR></TBODY></TABLE><BR>  在一个窗口中启动 host.exe 文件,然后在另一个窗口中启动 client.exe 文件。您将会看到事件被引发回到客户端。<BR><BR>  这是诸多 .NET Remoting 应用程序中的一个小例子。.NET Remoting 提供了网络上的完全 [url=http://whatis.ctocio.com.cn/searchwhatis/246/5947246.shtml]CLR[/url] 受控代码类型系统,它还是优秀的 SOAP 服务器和客户端,因为它完全符合 SOAP 1.1 规范。<BR><BR><BR>  <B><FONT color=#ac000>将 SOAP 用作 ATL 开发工具</FONT></B><BR><BR>  ATL Server <A href="http://dev.chinaitpower.com/dotnet/webservice/" target=_blank><FONT color=#0000ff>Web Service</FONT></A>s 为 C++ 开发人员提供了在本机代码中创建和使用 Web Services 的简便方式。ATL Server 是 C++ 开发人员在 Internet 上提供和使用 Web Services 的首选方法,其设计目的是为包含 SOAP 的 Web 应用提供快速、轻便和高度灵活的程序库。<BR><BR>  ATL Server 之所以称为 ATL,是因为它体现了同时追求高性能和灵活性的 ATL 目标。例如,您可以很容易地抛开 ATL Server HTTP 模型,编写您自己的调度程序,同时仍然获得 ATL Server 封送/协议代码的好处。<BR><BR>  ATL Server Web Services 使用与 COM 相似的语法说明接口,便于目前的 ATL 开发人员学习。这种与 COM 相似的语法允许开发人员轻而易举地将对象同时以 COM 对象和 Web Service 方式提供。<BR><BR>  属性的引入大大简化了代码,使它对于非 ATL 开发人员也很容易。ATL Server 具有和其他所有 .NET Web Services 进行互操作的能力,这对那些在一个应用程序中使用多种技术的开发人员来说十分方便。<BR><BR>  接口:新的 __interface 关键字使开发人员很容易创建 COM 对象或 Web Services 接口。<BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>[<BR>uuid("D7DAE6FD-AEBB-4579-BD8D-866F74139501"), <BR>object<BR>]<BR>__interface IWeb_Service_ExampleService<BR>{<BR>[id(1)] HRESULT HelloWorld([in] BSTR bstrInput, [out, retval] BSTR *bstrOutput);<BR>};</TD></TR></TBODY></TABLE><BR>  这是一个运用 ATL Server 定义 Web Service 接口的例子。通过 C++ 属性的运用,嵌入式 [url=http://whatis.ctocio.com.cn/searchwhatis/437/6025437.shtml]IDL[/url] 属性和新的 __interface 关键字、ATL Server Web Service 接口看起来和新的属性化的 COM 接口非常相似。这里的 Web Service 接口样例 IWeb_Service_ExampleService 仅实现一个方法 HelloWorld。HelloWorld 用 BSTR 作为输入并返回 BSTR 作为输出。<BR><BR>  请求处理程序:请求处理程序是一个 C++ 类,该类通过处理程序映射来提供,并且具有通过替代方法映射来提供的方法。处理程序映射只是文字标签与类名称的映射,而方法映射是类中文字标签与方法的映射。<BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>[<BR>request_handler(name="Default",sdl="GenWeb_Service_ExampleServiceSDL"),<BR>soap_handler(<BR>name="Web_Service_ExampleService", <BR>namespace="urn:Web_Service_ExampleService",<BR>[url=http://whatis.ctocio.com.cn/searchwhatis/343/6026343.shtml]protocol[/url]="soap"<BR>)<BR>]<BR>class CWeb_Service_ExampleService:<BR>public IWeb_Service_ExampleService<BR>{<BR>public:<BR><BR>[ soap_method ]<BR>HRESULT HelloWorld(BSTR bstrInput, BSTR *bstrOutput)<BR>{<BR>CComBSTR bstrOut(L"Hello ");<BR>bstrOut += bstrInput;<BR>bstrOut += L"!";<BR>*bstrOutput = bstrOut.Detach();<BR><BR>return S_OK;<BR>}<BR>};</TD></TR></TBODY></TABLE><BR>  ATL Server 请求处理程序模型与 Web 应用和 Web Services 非常相似。图 1 显示了处理请求的模型:<BR><BR>
<TABLE cellSpacing=0 cellPadding=0 width=600 align=center border=0>
<TBODY>
<TR>
<TD><IMG height=89 src="http://www.chinaitpower.com/A-A-A/2005/07/17/20050717083318114347_1.gif" width=615><BR>          图 1. ATL Server 请求处理模型 </TD></TR></TBODY></TABLE><BR>  HTTP Request 进入 IIS,将请求(基于 URL 及其扩展)映射到适当的 ISAPI DLL。然后,ISAPI DLL 把在请求中指定的处理程序(即在标签或查询参数中指定的处理程序)映射到适当的 Application DLL。Application DLL 再将这个处理程序映射到 C++ 对象。在这个模型(ATL Server 模型)中,Web 应用程序和 Web Service 的唯一差别在于最后一步。使用 Web Services,C++ 对象能够解码/编码 SOAP(当编译器解析 soap_handler 属性时,它会插入执行此操作的代码)。<BR><BR>  您可以理解,这个类是从我们的接口继承过来的,并且我们使用 [soap_method] 属性指示将由 HelloWorld 方法来处理 SOAP 请求。实现这种方法和实现任何其他 C++ 方法是一样的。<BR><BR>  这个 soap_handler 属性还确保自动生成有效说明服务的 WSDL。Web Service 的用户使用这个对服务的说明(格式为 XML/WSDL),确保他们能够以正确的格式发送/接收正确的数据。<BR><BR>  <B><FONT color=#ac000>通过 ATL Server 使用 Web Services</FONT></B><BR><BR>  通过 ATL Server 使用 Web Services 相对来说是个比较简单的操作。开发人员只需使用 “Add Web Reference” 对话框,将它指向 .disco 文件,然后指向 WSDL,这和使用其他类型的 Web 引用一样。这个对话框在后台运行在 Web Service 的 WSDL 上的 sproxy.exe 实用程序(对于非本机的 .NET Web Services 有另外一个实用程序)。<BR><BR>  该操作将创建 Web Service 代理文件,包含要求利用所请求的 Web Service 的全部 C++ 代码。使用 WSDL 中的信息,代理生成器能够判断 Web Service 要接收到的数据以及它要返回给客户端的数据。这就允许代理生成器创建可以和 Web Service“交谈”的头文件。<BR><BR>  您只需创建自己的 Web Service 类(如在生成的头文件中查找到的一样)的实例,并且使用合适的方法即可,例如:<BR><BR>
<TABLE class=txcode cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>CWeb_Service_ExampleServiceService MyService;<BR>CComBSTR bstrOut;<BR>CComBSTR bstrIn(L"World");<BR>MyService.HelloWorld ( bstrIn ,&amp;bstrOut,);<BR>wprintf(bstrOut);</TD></TR></TBODY></TABLE><BR>  现在,您就已经有一个基本的 ATL Server Web Service 和 ATL Server Web Service Consumer 了。<BR><BR> <B><FONT color=#ac000> 总结</FONT></B><BR><BR>  本文的主要目的是对 .NET 框架和 Visual Studio.NET 中的 SOAP 功能作一个总体的介绍。其次,就如何创建使用 SOAP 的应用程序,给用户一些有益的指导。<BR>
页: [1]
查看完整版本: .NET框架和VS.NET中的SOAP