答案: 使用高层API发送和接收SOAP消息
在这个简单的例子中,服务器提供简单的算术服务:加法,减法,显示字符串(仅仅把输入的字符串回显出来)。为了创建这个应用程序,你需要在服务器和客户端创建不同的组件。在服务器这一端,你需要:
创建一个ActiveX DLL
创建一个WSDL文件列出服务以及服务中的操作
创建一个WSML文件,把WSDL中描述的服务的操作对应到COM对象的方法
创建一个ASP文件,处理SOAP请求
在客户端,你需要:
写一个VBScript调用服务器提供的操作
在客户端和服务器端,这个简单的应用使用了高层API,例如 SoapClient 和 SoapServer 来发送和接受消息。
在服务器端做以下工作
创建一个ActiveX DLL
打开VB,创建一个ActiveX DLL工程(注意,这个服务器上要安装IIS)
把工程名改为DocSample1,类名改为Sample1
在Sample1类中,添加以下代码:
Public Function EchoString(ByVal testString As String) _
As String
EchoString = testString
End Function
Public Function AddNumbers(ByVal NumberOne As Double, _
ByVal NumberTwo As Double) _
As Double
AddNumbers = NumberOne + NumberTwo
End Function
Public Function SubtractNumbers(ByVal NumberOne As Double, _
ByVal NumberTwo As Double) _
As Double
SubtractNumbers = NumberOne - NumberTwo
End Function
选择菜单项 Make DocSample1.dll创建DLL文件
创建虚拟路径
在IIS环境下,创建一个Web虚拟路径,叫DocSample1
创建WSDL文件
在运行IIS的服务器上,把下面的文件DocSample1.wsdl复制到刚才建立的DocSample1路径下
DocSample1.wsdl文件:
<?xml version=’1.0’ encoding=’UTF-16’ ?>
<definitions name =’DocSample1’ targetNamespace = ’http://localhost/DocSample1/DocSample1.wsdl’
xmlns:tns=’http://localhost/DocSample1/DocSample1.wsdl’
xmlns:xsd1=’http://localhost/DocSample1/DocSample1.xsd’
xmlns:soap=’http://schemas.xmlsoap.org/wsdl/soap/’
xmlns=’http://schemas.xmlsoap.org/wsdl/’>
<types>
<schema
targetNamespace=
’http://localhost/DocSample1/DocSample1.xsd’
xmlns=’http://www.w3.org/1999/XMLSchema’>
</schema>
</types>
<message name=’EchoString’>
<part name=’testString’ type=’string’/>
</message>
<message name=’EchoStringResponse’>
<part name=’Result’ type=’string’/>
</message>
<message name=’AddNumbers’>
<part name=’NumberOne’ type=’double’/>
<part name=’NumberTwo’ type=’double’/>
</message>
<message name=’AddNumbersResponse’>
<part name=’Result’ type=’double’/>
</message>
<message name=’SubtractNumbers’>
<part name=’NumberOne’ type=’double’/>
<part name=’NumberTwo’ type=’double’/>
</message>
<message name=’SubtractNumbersResponse’>
<part name=’Result’ type=’double’/>
</message>
<portType name=’DocSample1PortType’>
<operation name=’EchoString’ parameterOrder=’EchoStringInput1’>
<input message=’tns:EchoString’ />
<output message=’tns:EchoStringResponse’ />
</operation>
<operation name=’AddNumbers’
parameterOrder=’AddNumbersInput1 AddNumbersInput2’>
<input message=’tns:AddNumbers’ />
<output message=’tns:AddNumbersResponse’ />
</operation>
<operation name=’SubtractNumbers’
parameterOrder=’SubtractNumbersInput1 SubtractNumbersInput2’>
<input message=’tns:SubtractNumbers’ />
<output message=’tns:SubtractNumbersResponse’ />
</operation>
</portType>
<binding name=’DocSample1Binding’ type=’tns:DocSample1PortType’ >
<soap:binding style=’rpc’
transport=’http://schemas.xmlsoap.org/soap/http’ />
<operation name=’EchoString’ >
<soap:operation
soapAction=’http://localhost/DocSample1/DocSample1.asp’ />
<input>
<soap:body use=’encoded’
namespace=’http://localhost/DocSample1/DocSample1.xsd’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’ />
</input>
<output>
<soap:body use=’encoded’
namespace=’http://localhost/DocSample1/DocSample1.xsd’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’ />
</output>
</operation>
<operation name=’AddNumbers’ >
<soap:operation
soapAction=’http://localhost/DocSample1/DocSample1.asp’ />
<input>
<soap:body use=’encoded’
namespace=’http://localhost/DocSample1/DocSample1.xsd’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’ />
</input>
<output>
<soap:body use=’encoded’
namespace=’http://localhost/DocSample1/DocSample1.xsd’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’ />
</output>
</operation>
<operation name=’SubtractNumbers’ >
<soap:operation
soapAction=’http://localhost/DocSample1/DocSample1.asp’ />
<input>
<soap:body use=’encoded’
namespace=’http://localhost/DocSample1/DocSample1.xsd’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’ />
</input>
<output>
<soap:body use=’encoded’
namespace=’http://localhost/DocSample1/DocSample1.xsd’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’ />
</output>
</operation>
</binding>
<service name=’DocSample1’ >
<port name=’DocSample1PortType’ binding=’tns:DocSample1Binding’ >
<soap:address
location=’http://localhost/DocSample1/DocSample1.asp’ />
</port>
</service>
</definitions>
上一个:跟我学XSL(二)
下一个:XML指南——XML编码