实例学习MS SOAP Toolkit 3.0 与 Web Service

类别:编程语言 点击:0 评论:0 推荐:

实例学习MS SOAP Toolkit 3.0 与 Web Service

Herosword 原创

 

一.   MS SOAP Toolkit 3.0 下载和安装

在微软的网站上可以下载到该工具.安装选择默认安装。

 

二.   设置IIS虚拟目录

在MS SOAP Toolkit 3.0中, ISAPI 处理程序为 SOAPIS30.DLL 文件

安装好 SOAP Toolkit 3.0后, 有一个文件 SOAPVDIR.CMD可以帮助我们设置虚拟目录

,并SOAPIS30.DLL与该目录中对 .WSDL文件的请求做关联,也可以手工设置IIS目录,并配置目录属性, 加入SOAPIS30.DLL做为 .WSDL请求的处理程序.

 

使用 SOAPVDIR.CMD 脚本工具:

命令格式:

SOAPVDIR [command vdirname [directory path]] [-s: server] [-w: root]

具体命令可以用 SOAPVDIR.CMD HELP来查看.

 

手工建立 .WSDL与SOAPIS30.DLL的映射

打开IIS, 选择一个站点或虚拟目录,右键选择属性:在主目录或虚拟目录中选择应用程序设置,如图:

 



点击添加,为WSDL文件增加一种应用程序映射。

在可执行文件输入框输入:

C:\PROGRA~1\COMMON~1\MSSOAP\BINARIES\SOAPIS30.DLL

在扩展名输入框输入:.WSDL

选择限于:GET,POST,HEAD

(如图)

 



点击确认:(如图)



以上步骤,实际上是为Server配置了一个ISAPI Listener, 还可以配置一种Listener, ASP Listener.

 

三.开发和部署一个Web Service

       首先建立一个ATL工程,实现一个Simple Object接口

 


编译成功后,用SOAPToolkit 3.0的WSDL Generator工具,生成 WebService的WSDL和WSML,生成的文件保存到刚才设置的IIS的虚拟目录中。

 

 

三.   用 SOAPClient30 Object 开发 SOAP客户端程序

SOAPClient Object实现在MSSOAP30.DLL中,我们需要引入 MSSOAP30.DLL类型库

 

#import "C:\WINNT\system32\msxml4.dll"

using namespace MSXML2;

 

#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \

            exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \

                    "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")

using namespace MSSOAPLib30;

 

 

 

// TestClient.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

 

void Add()

{

    ISoapSerializerPtr Serializer;

    ISoapReaderPtr Reader;

    ISoapConnectorPtr Connector;

 

    // Connect to the service.

    Connector.CreateInstance(__uuidof(HttpConnector30));

    Connector->Property["EndPointURL"] =         "http://172.16.245.62:8090/myws/MyTestService.WSDL";

    Connector->Connect();

 

    // Begin the message.

    //Connector->Property["SoapAction"] = "uri:AddNumbers";

    Connector->Property["SoapAction"] = "http://org.kylin.test/MyTestService/action/Math.Add";

    Connector->BeginMessage();

 

    // Create the SoapSerializer object.

    Serializer.CreateInstance(__uuidof(SoapSerializer30));

 

    // Connect the serializer object to the input stream of the connector object.

    Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

 

    // Build the SOAP Message.

    Serializer->StartEnvelope("","","");

    Serializer->StartBody("");

    Serializer->StartElement("Add","http://org.kylin.test/MyTestService/message/","","");

    Serializer->StartElement("lOp1","","","");

    Serializer->WriteString("2");

    Serializer->EndElement();

    Serializer->StartElement("lOp2","","","");

    Serializer->WriteString("13");

    Serializer->EndElement();

    Serializer->EndElement();

    Serializer->EndBody();

    Serializer->EndEnvelope();

 

    // Send the message to the XML Web service.

    Connector->EndMessage();     

 

    // Read the response.

    Reader.CreateInstance(__uuidof(SoapReader30));

 

    // Connect the reader to the output stream of the connector object.

    Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");

 

    // Display the result.

    printf("Answer: %s\n", (const char*)Reader->RpcResult->text);

}

 

int main(int argc, char* argv[])

{

    CoInitialize(NULL);

 

    Add();

 

    CoUninitialize();

 

    return 0;

}

 

本文地址:http://com.8s8s.com/it/it24202.htm