VC6.0下调用Webservice
来源:互联网 发布:情系探花头像psd源码 编辑:程序博客网 时间:2024/06/11 16:12
1、先安装soapsdk3.0(http://download.microsoft.com/download/2/e/0/2e068a11-9ef7-45f5-820f-89573d7c4939/soapsdk.exe)
2、编写WSWrapper.h
#ifndef _WS_WRAPPER_H_
#define _WS_WRAPPER_H_
#import "msxml4.dll"
#import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
#include <string>
#include <Windows.h>
using namespace MSXML2;
using namespace MSSOAPLib30;
using std::string;
class WSWrapper
{
public:
WSWrapper(const char *wsURL,
const char *wsNameSapce,
const char *wsMethodName);
virtual ~WSWrapper();
string Hello(const string &strName);
private:
const string _wsURL;
const string _wsNameSapce;
const string _wsMethodName;
};
#endif
3、编写WSWrapper.cpp
#include "WSWrapper.h"
WSWrapper::WSWrapper(const char *wsURL, const char *wsNameSapce, const char *wsMethodName)
: _wsURL(wsURL),_wsNameSapce(wsNameSapce), _wsMethodName(wsMethodName)
{
}
WSWrapper::~WSWrapper()
{
}
string WSWrapper::Hello(const string &strName)
{
try
{
printf("2\n");
HRESULT hr = CoInitialize(NULL);//初始化com环境
if(FAILED(hr))
{
//出错了
}
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
//连接到WebService
hr = Connector.CreateInstance(__uuidof(HttpConnector30));
printf("3\n");
if(FAILED(hr))
{
//创建com对象出错,一般是因为没有安装com
}
Connector->Property["EndPointURL"] = _wsURL.c_str();
Connector->Connect();
Connector->Property["SoapAction"] = (_wsNameSapce + _wsMethodName).c_str();
//开始创建webservice的请求Soap包
Connector->BeginMessage();
printf("4\n");
hr = Serializer.CreateInstance(__uuidof(SoapSerializer30));
printf("5\n");
if(FAILED(hr))
{
//创建com对象出错,一般是因为没有安装com
printf("failed!\n");
return "";
}
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
printf("51\n");
Serializer->StartEnvelope("SOAP", "http://schemas.xmlsoap.org/soap/envelope/", "");
Serializer->SoapAttribute("xsi", "", "http://www.w3.org/2001/XMLSchema-instance", "xmlns");
Serializer->SoapAttribute("xsd", "", "http://www.w3.org/2001/XMLSchema", "xmlns");
Serializer->StartBody(L"NONE");
printf("52\n");
Serializer->StartElement(_wsMethodName.c_str(), _wsNameSapce.c_str(), "NONE", "");
Serializer->StartElement(L"strName", "", "NONE", "");
Serializer->SoapAttribute("xsi:type", "", "xsd:string", "");
Serializer->WriteString(strName.c_str());
printf("53\n");
Serializer->EndElement();
Serializer->EndElement();
Serializer->EndBody();
printf("54\n");
Serializer->EndEnvelope();
printf("55\n");
Connector->EndMessage();
printf("6\n");
//解析返回的soap包
hr = Reader.CreateInstance(__uuidof(SoapReader30));
printf("7\n");
if(FAILED(hr))
{
//创建com对象出错,一般是因为没有安装com
}
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
printf("8\n");
string strResult((const char*)Reader->RpcResult->text);
return strResult;
}
catch(_com_error e)
{
//got a exception
printf(e.Description());
printf("\n");
printf("FAILED!");
return "error";
}
}
4、Webservice 测试例子:testWebservice.cpp
#include "stdafx.h"
#include "WSWrapper.h"
int main(int argc, char* argv[])
{
printf("test...\n");
WSWrapper wsWrapper("http://localhost/TestWebService/Service1.asmx",
"http://localhost/TestWebService/",
"Hello");
printf("1\n");
string strName = "Lucy";
string strResult = wsWrapper.Hello(strName);
printf("11\n");
printf("%s", strResult.c_str());
getchar();
return 0;
}
- VC6.0下调用Webservice
- vc6.0调用webservice天气
- VC6.0调用webservice方法
- VC6.0调用ASP.NET WebService示例
- vc6里调用WebService
- vc6里调用WebService
- vc6如何调用WEBSERVICE
- VC6.0下访问WebService的组件
- 在vc6里调用WebService
- 转帖--VC6.0调用ASP.NET WebService实例
- vc6控制台程序利用SoapToolkit3.0调用WebService
- vc6.0连接webservice
- VC6.0调用WebService,传如参数后,返回的结果出错"soap:Server",
- win7 mysql数据库安装于vc6.0下数据库调用
- .net下Javascript调用webservice
- VS2012下开发调用WebService
- VC6.0下编译
- vc6.0 调用ocx控件
- 【第六章】 AOP 之 6.5 AspectJ切入点语法详解 ——跟我学spring3
- 查看Linux系统 重启日志,登录日志和输入命令的日志
- Linux下插件开发应用案例
- 软件随想录(local.joelonsoftware.com/wiki)-2006年09月01日 语言战争 - Language Wars
- C++中派生类访问基类protected成员的范围
- VC6.0下调用Webservice
- Linux下expect的ssh自动登录脚本
- input_dev 结构体成员注释
- 软件随想录(local.joelonsoftware.com/wiki)-2006年09月12日 再探Ruby效能 - Ruby Performance Revisited
- MyEclipse和Eclipse在使用中的问题
- 【第六章】 AOP 之 6.6 通知参数 ——跟我学spring3
- Difference between GWAS/MAS and GS
- Qt中无法load big image的问题
- 资源