MSXML + SOAP TOOLKIT调用Web Service C++例子。

19 篇文章 0 订阅
此博客展示了如何在C++中利用MSXML库和SOAP Toolkit来连接并调用Web Service。通过创建ISoapSerializer和ISoapReader对象,构建并发送SOAP消息到指定的URL,然后读取并显示服务响应。
摘要由CSDN通过智能技术生成

#include <stdio.h>

#import "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;

void Add()

{

   ISoapSerializerPtr Serializer;

   ISoapReaderPtr Reader;

   ISoapConnectorPtr Connector;

   // Connect to the service.

   Connector.CreateInstance(__uuidof(HttpConnector30));

   Connector->Property["EndPointURL"] = "http://MyServer/Soap3DocSamples/DocSample1/Server/DocSample1.wsdl";

   Connector->Connect();

 

   // Begin the message.

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

   Connector->Property["SoapAction"] = "http://tempuri.org/DocSample1/action/Sample1.AddNumbers";

   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("AddNumbers","http://tempuri.org/DocSample1/message/","","");

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

   Serializer->WriteString("5");

   Serializer->EndElement();

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

   Serializer->WriteString("10");

   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()

{

   CoInitialize(NULL);

   Add();

   CoUninitialize();

   return 0;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值