Com组件提供Web Services(二)

** Com 组件提供 Web Service(二)
** 追风 (VisualSW)

选择生成文件的路径。

点击下一步

9 .

生成文件成功。

打开生成文件的目录,可以看到多了以下文件:

** 注册 ** ** IIS ** ** 监听 ** ** **

1 .打开 IIS MMC ,新建一个虚拟目录指向刚才生成的文件地址。

2 .进入 Windows cmd ,进入 C:\Program Files\MSSOAP\Binaries 输入下面命令 c:>soapvdir.cmd UPDATE DLLServices 改命令注册一个 ISAPI DLL 来监听请求。

这样 Com 组件就开始提供 WEB 服务了,下面来测试一下

打开 VB ,创建工程,添加 Soap 引用

添加如下代码:

Dim oSoapClient


Dim nResult


 


Set oSoapClient = CreateObject ("MSSOAP.SoapClient30")


If (Err <> 0) Then


            MSgBox "Initialization of the SOAP Toolkit failed."


            Return


End If


 


Call oSoapClient.MsSoapInit ("http://localhost/DLLServices/DLLService.WSDL", "MyService", "")


If (Err <> 0) Then


            MSgBox "Error initializing the WSDL file."


            Return


End If


 


nResult = oSoapClient.Add (3, 4)


MsgBox "Result of 3+4 = " & CStr(nResult)


 


Set oSoapClient = Nothing


 


如果能看到结果则表示使Com组件提供Web Service成功

创建组件的 .NET 代理类

还是使用上面例子中的 VBDLL.dll 组件。

微软的 .NET Framework 提供了一个工具 Type Library Importer (Tlbimp.exe) ,用来将 Com 组件封装为一个 .NET 的 assembly ,这样就可以在 VS.NET 中使用封装好的 VBDLL.dll 的 .NET 代理类了。

1 .生成代理类

_ _ _ F:\SW\MS.NET\Web Services\VB>"D:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\tlbimp.exe" vb _ _ dll _ _ .dll /out:vb_proxy.dll _

_ Microsoft (R) .NET Framework Type Library to Assembly Converter 1.0.3705.0 _

_ Copyright (C) Microsoft Corporation 1998-2001. All rights reserved. _

_ Type library imported to F:\SW\MS.NET\Web Services\VB\vb _ _ dll _ _ _proxy.dll _

这样就在当前目录下生成了 vbdll_proxy.dll 的 .net assembly ,

我们使用 Intermediate Language Disassembler (Ildasm.exe) 可以看到 assembly 的信息,

2 .打开 VS.NET ,新建 ASP.NET Web Service

3. 添加 vbdll_proxy.dll 的引用

4 .添加 Web 方法

[WebMethod]

public int Add( int a, int b)

{                                              

vb_proxy.clsAddClass obj= new vb_proxy.clsAddClass();

return obj.Add(( short )a,( short )b);
}

5 .编译 Web Service 。

6 .测试,同上列

结束语:

两种方法都可以实现 Com 组件提供 Web 服务,相比起来第二种方法简单一些。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus