vc6.0调用webservice天气

首先应该安装soap toolkit3.0

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13456

运行环境为windows xp sp3,无需配置其它任何环境,直接运行以下代码即可。

#include  <stdio.h>    

#include "windows.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()    

{  

CoInitialize(NULL); 

         ISoapSerializerPtr   Serializer;  

         ISoapReaderPtr   Reader;  

         ISoapConnectorPtr   Connector;  

         //   Connect  to   the   service.  

         ifFAILED(Connector.CreateInstance(__uuidof(HttpConnector30)))    //创建对象

         {

                   printf("失败");

         }

         Connector->Property["EndPointURL"] ="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";    //wsdl路径

         Connector->Connect();  

 

         //   Begin  the   message.  //消息体

         Connector->Property["SoapAction"]   = "http://WebXml.com.cn/getWeather"; //函数体参数

         Connector->BeginMessage(); 

 

         Serializer.CreateInstance(__uuidof(SoapSerializer30));      

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

 

         //   Build  the   SOAP   Message.

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

         Serializer->StartBody("");  

         Serializer->StartElement("getWeather","http://WebXml.com.cn/","","Soap");  //函数处理

         Serializer->StartElement("theCityCode","","","Soap");

         Serializer->WriteString("南京");          //参数处理      

         Serializer->EndElement();

         Serializer->EndElement();

         Serializer->EndBody();  

         Serializer->EndEnvelope();  

        

         Connector->EndMessage();        

         Reader.CreateInstance(__uuidof(SoapReader30));  

         printf("here");

         Reader->Load(_variant_t((IUnknown*)Connector->OutputStream),"");  //加载返回数据

         //   Display  the   result.

         //printf("Answer:%s\n", (const char*)Reader->Body->xml);

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

 

}    

 

int  main()    

{    

CoInitialize(NULL);    

Add();    

CoUninitialize();    

return  0;    

}   

 

附注:1、当无输入参数时,需要删除以下三条语句:

Serializer->StartElement("theCityCode","","","Soap");

Serializer->WriteString("南京");          //参数处理      

Serializer->EndElement();

2、当webservice为java所写时:

(1)Connector->Property["EndPointURL"]为函数所在页面的地址,如:

http://192.168.1.9:7001/leohis/services/GetTime

(2)Connector->Property["SoapAction"]可以同上,也可以去掉”/GetTime”

(3)Serializer->StartElement("getWeather","http://WebXml.com.cn/","","Soap")中的第二个参数为wsdl界面文件中的”targetNamespace”

3、当webservice为asp.net所写,则按照上面的程序来写。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值