下面是个控制台的样例
Toolkit3.0 终于给出VC6的样例了,1.0只能看到VB和ASP的
#include
1<stdio.h>
2
3#import "msxml4.dll"
4using namespace MSXML2;
5
6#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
7exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \
8"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
9using namespace MSSOAPLib30; //你机器得安装SOAP Toolkit3.0 ,1.0时,用using namespace时报错
10
11
12void Add()
13{
14ISoapSerializerPtr Serializer;
15ISoapReaderPtr Reader;
16ISoapConnectorPtr Connector;
17// Connect to the service.
18Connector.CreateInstance(__uuidof(HttpConnector30)); **//HttpConnector30 失败,无法这样创建 Connector ,CXX0017 Error :Symbol “HttpConnector30“ not found(摇头、叹气!)
19** Connector->Property["EndPointURL"] = " http://MyServer/Soap3DocSamples/DocSample1/Server/DocSample1.wsdl "; //这个当然得改成您自己的拉
20Connector->Connect();
21
22// Begin the message.
23//Connector->Property["SoapAction"] = "uri:AddNumbers";
24Connector->Property["SoapAction"] = " http://tempuri.org/DocSample1/action/Sample1.AddNumbers ";
25Connector->BeginMessage();
26
27// Create the SoapSerializer object.
28Serializer.CreateInstance(__uuidof(SoapSerializer30));
29
30// Connect the serializer object to the input stream of the connector object.
31Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
32
33// Build the SOAP Message.
34Serializer->StartEnvelope("","","");
35Serializer->StartBody("");
36Serializer->StartElement("AddNumbers"," http://tempuri.org/DocSample1/message/ ","",""); //这是本地的Web Services,实际中要指定命名空间
37Serializer->StartElement("NumberOne","","","");
38Serializer->WriteString("5");
39Serializer->EndElement();
40Serializer->StartElement("NumberTwo","","","");
41Serializer->WriteString("10");
42Serializer->EndElement();
43Serializer->EndElement();
44Serializer->EndBody();
45Serializer->EndEnvelope();
46
47// Send the message to the XML Web service.
48Connector->EndMessage();
49
50// Read the response.
51Reader.CreateInstance(__uuidof(SoapReader30));
52
53// Connect the reader to the output stream of the connector object.
54Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
55
56// Display the result.
57printf("Answer: %s\n", (const char*)Reader->RpcResult->text);
58
59}
60
61int main()
62{
63CoInitialize(NULL);
64Add();
65CoUninitialize();
66return 0;
67}
68
69更改 EndPointURL 属性的值. 在URL里指定你的服务器名.
70
71OK
72
73总结一下必要的关键步骤
741.导入类型库
75
762.需要创建一个SoapConnector
77
783.下一步创建SoapSerializer
79
804.下一步把消息附加到SoapConnector的输入流
81
825.下一步读取结果.要读取服务器的回复,客户端应用需要使用SoapReader,
83
846.SoapReader被连接到SoapConnector输出流
85
867.用IXMLDOMElement对象可以从SoapReader里读到服务器的回复
87
88附,SOAP ToolKit 3.0 下载地址: http://download.microsoft.com/download/xml/Install/3.0/W982KMeXP/EN-US/SoapToolkit30.EXE</stdio.h>