c#创建webService, vc++ 调用
来源:互联网 发布:qq三国79js打架技巧 编辑:程序博客网 时间:2024/05/17 22:51
1、安装 SoapToolkit
2、CString bBackQuestion;
bBackQuestion =(const char*)Reader->Body->xml; //可以查看错误原因,
3、不能识别http头,导致返回Soap::Client问题,需要c#创建WebService时,添加申明
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
代码如下:(代码未经整理,不能直接运行。。。vc++用户可以稍微修改下即可)
c#代码不需要修改,直接创建 ASP WEB复制即可
c#
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections;
using System.Runtime.InteropServices;
[WebService(Namespace = "http://mywebservice/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
//[System.Web.Services.Protocols.SoapRpcService]
public class Service : System.Web.Services.WebService
{
public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
//返回提取新号码的一些信息
public string test()
{
return "succeful~";
}
}
vc++: .h
#import "msxml4.dll"
#import "mssoap30.dll" \
exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSXML2;
using namespace MSSOAPLib30;
.cpp
CString CFD_Soap::strGet_DataSet(LPCTSTR lFunc, LPCTSTR pParam)
{
CString strFunc(_T("")), strParam(_T(""));
if(lFunc == NULL)
strFunc = m_strFunc;
if (strFunc.IsEmpty())
return _T("");
if (pParam)
strParam = pParam;
else
strParam = m_strParam;
m_strURL = "http://localhost/Queue/Service.asmx";
m_strNs = "http://mywebservice/";
strFunc = _T("webGetSrv");
CString strResult(_T(""));
HRESULT hr = CoInitialize(NULL);//³õʼ»¯com»·¾³
if(FAILED(hr))
return _T("");
ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
try
{
//Á¬½Óµ½WebService
hr = Connector.CreateInstance(__uuidof(HttpConnector30));
if(FAILED(hr))
return strResult;
Connector->Property["EndPointURL"] = (_variant_t)m_strURL;
hr = Connector->Connect();
Connector->Property["SoapAction"] = "";//(_variant_t)m_strNs;
//¿ªÊ¼´´½¨webserviceµÄÇëÇóSoap°ü
hr = Connector->BeginMessage();
hr = Serializer.CreateInstance(__uuidof(SoapSerializer30));
if(FAILED(hr))
return strResult;
hr = Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
hr = Serializer->StartEnvelope("", "", "");
hr = Serializer->StartBody("");
hr = Serializer->StartElement((_bstr_t)strFunc, (_bstr_t)m_strNs, "", "");
if(!strParam.IsEmpty())
{
Serializer->StartElement("info", (_bstr_t)m_strNs, "", "");
Serializer->WriteString((_bstr_t)strParam);
Serializer->EndElement();
}
hr = Serializer->EndElement();
hr = Serializer->EndBody();
hr = Serializer->EndEnvelope();
hr = Connector->EndMessage(); //ÉÏ´«ÇëÇó
//½âÎö·µ»ØµÄsoap°ü
hr = Reader.CreateInstance(__uuidof(SoapReader30));
if(FAILED(hr))
return strResult;
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
strResult = (LPCTSTR)Reader->RpcResult->text;
CString bBackQuestion;
bBackQuestion =(const char*)Reader->Body->xml;
}
catch (_com_error& e)
{
CString bBackQuestion;
bBackQuestion =(const char*)Reader->Body->xml; //ʧ°ÜÔÒò
TRACE(e.ErrorMessage());
return _T("") ;
}
return strResult;
}
- c#创建webService, vc++ 调用
- C#创建和调用WebService
- C#创建和调用WebService
- C#创建和调用WebService
- 使用C#创建webservice及调用方式
- 使用C#创建webservice本地调用方式
- 使用XFire创建WebService实例、C#调用
- C#创建和调用WebService详细教程
- C#创建与调用Webservice基础
- VS2010 c#创建及调用Webservice
- C#创建和调用WebService详细教程
- C#创建和调用WebService详解
- C#创建和调用WebService详细教程
- VS2010 c#创建及调用Webservice
- C#创建和调用WebService详细教程
- C#创建和调用WebService详细教程
- VC++ 创建和调用WebService 图文教程 相关资料等
- VC 2010 使用GSOAP调用C#写的WEBSERVICE
- eclipse 用空格替换 tab键
- [openstack swift]3 其他相关(2)
- 如何快速学会使用协议
- 标准软件测试工作流程解析
- 整理索引碎片,提升SQL Server速度
- c#创建webService, vc++ 调用
- STDMETHOD介绍
- 取BOM的相关信息报表。
- STL运用的C++技术(2)——模板特化
- 【转】Spring中bean的配置
- 把字符串分割成固定长度的片段,返回数组
- NESTED LOOPS 成本计算
- 【转】张冰OGNL表达式
- 在查询语句中使用 NOLOCK 和 READPAST