gsoap uscore i7 接口会影响接口使用吗

拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(3a7ecb-ua98).
重新安装浏览器,或使用别的浏览器下次自动登录
现在的位置:
& 综合 & 正文
WCF over JMS(ActiveMQ) 与 gSoap over JMS(ActiveMQ) 通信总结
WCF over JMS 与 gSoap over JMS 通信总结
一共有三个项目:
项目1:WCFServiceLibrary
项目2:C++的Server
项目3:C#的Client
步骤一:定义接口(项目1)
把项目2调用项目3的接口和项目3调用项目2的接口都集成到项目1里,接口可以为Request/Response模式和OneWay模式,接口实现为空,BasicHttpBinding
步骤二:项目2使用接口
1、在某个文件夹下放入gSoap包内的三个文件wsdl2h.exe,soapcpp2.exe,typemap.dat和三个文件夹import,extras,custom
2、运行项目1,获取wsdl地址,用gSoap提供的工具wsdl2h.exe生成接口头文件gSoap.h
cmd: wsdl2h.exe -o gSoap.h
3、用gSoap提供的工具soapcpp2.exe生成C++需要的代理文件
cmd: soapcpp2.exe -1 -i -x -a -IimportgSoap.h
-1 代表使用SOAP1.1协议,-i代表生成C++代理类,-x代表不生成xml文件,-a代表加入action检查,-Iimport代表使用import文件夹内的文件,其中import中的文件又会牵扯到另两个文件夹
4、删除gSoap.h文件。
第2到4步可以用一个bat文件代替,bat文件存放在当前文件夹,内容为:
wsdl2h.exe -o gSoap.hhttp://localhost:6666/Interface/Service/?wsdl
soapcpp2.exe -1 -i -x -a -Iimport gSoap.h
del gSoap.h
5、双击bat文件生成soapH.h、soapC.cpp、soapStub.h、-.nsmap、-Proxy.h、-Proxy.cpp、-Service.h、-Service.cpp共八个文件。把这八个文件放到项目2的一个gSoap文件夹下,并把gSoap包提供的stdsoap2.h、stdsoap2.cpp、duration.h、duration.cpp也放到此文件夹内
6、修改stdsoap2.cpp文件,添加宏(若不添加此宏,链接时会出错,算是gSoap的bug):
#ifndef WITH_NONAMESPACES
#define WITH_NONAMESPACES
7、修改duration.cpp文件,此文件中只有xsd系列的5个函数,仿照着写出ns3系列的函数。这应该是gSoap的一个bug,如果不实现这五个函数,链接会出错
8、修改-Proxy.h、-Proxy.cpp文件。删除本项目作为服务端的代码
9、修改-Service.h、-Service.cpp文件。删除本项目作为客户端的代码。实现其他接口
10、项目2引入此文件夹及这12个文件,即可实现Http通信功能。
11、实现over JMS功能。加入JMS封装类QueueProducer、QueueConsumer、TopicProducer。在-Proxy.cpp、-Service.cpp文件中,把通信底层换成JMS。
Service端函数:
static int serve___ns1__Fun(BasicHttpBinding_USCOREIServiceService*soap)
struct__ns1__Fun soap_tmp___ns1__F
_ns1__FunResponsens1__FunR
ns1__FunResponse.soap_default(soap);
soap_default___ns1__Fun(soap,&soap_tmp___ns1__Fun);
soap-&encodingStyle= NULL;
if(!soap_get___ns1__Fun(soap, &soap_tmp___ns1__Fun, "-ns1:Fun",NULL))
return soap-&
if(soap_body_end_in(soap)
|| soap_envelope_end_in(soap)
|| soap_end_recv(soap))
{/*returnsoap-&*/}
soap-&error= soap-&Fun(soap_tmp___ns1__Fun.ns1__Fun, &ns1__FunResponse);
soap-&action= "http://tempuri.org/IService/FunResponse";
soap-&mode= 1;
soap-&bufidx= 0;
soap-&ns= 0;
memset(soap-&buf,0, 65536);
if(soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| ns1__FunResponse.soap_put(soap,"ns1:FunResponse", "")
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap-&
soap-&buflen= soap-&
Proxy端函数:
int BasicHttpBinding_USCOREIServiceProxy::Fun(constchar *endpoint, const char *soap_action, _ns1__Fun *ns1__Fun, _ns1__FunResponse*ns1__FunResponse)
structsoap *soap =
struct__ns1__Fun soap_tmp___ns1__F
soap_tmp___ns1__Fun.ns1__Fun= ns1__F
soap-&action= "http://tempuri.org/IService/Fun";
memset(soap-&buf,0, 65536);
soap-&mode= 1; // 消息添加进buf中而不是显示在屏幕上
soap-&ns= 0; // 添加头
soap-&bufidx= 0;
if(soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put___ns1__Fun(soap,&soap_tmp___ns1__Fun, "-ns1:Fun", NULL)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap-&
// 发送消息并接收响应
stringqstrSendMSG = string(soap-&buf, soap-&bufidx);
stringqstrReturnMSG;
m_pQueueProducer-&SendQueueMessage(qstrSendMSG,qstrReturnMSG);
if(qstrReturnMSG.empty())
intnLength = qstrReturnMSG.length();
strncpy(soap-&buf,qstrReturnMSG.c_str(), nLength);
soap-&bufidx= 0;
soap-&buflen= nL
soap-&mode= 0;
soap-&peeked= 0;
soap-&ahead= 0;
if(soap_envelope_begin_in(soap)
|| soap_recv_header(soap)
|| soap_body_begin_in(soap))
return soap-&
ns1__FunResponse-&soap_get(soap,"ns1:FunResponse", "");
12、-Service类中加入一个函数disposeBuf,当接收到JMS消息时,把消息内容复制到soap-&buf中,然后进行dispatch(),决定到底使用哪个接口
void QueueConsumer::onMessage( const Message* message) throw() {
const TextMessage* textMessage =
dynamic_cast&const TextMessage* &( message );
std::string text = "";
if( textMessage != NULL )
text= textMessage-&getText().c_str();
if(text.empty())
m_pService-&disposeBuf(text);
std::string qstrReplyMSG =std::string(m_pService-&buf, m_pService-&buflen);
voidBasicHttpBinding_USCOREIServiceService::disposeBuf(std::string strMSG)
intnLength = strlen(strMSG.c_str());
memset(this-&buf,0, 65536);
strncpy(this-&buf,strMSG.c_str(), nLength);
this-&buflen= nL
this-&bufidx= 0;
soap_envelope_begin_in(this);
soap_recv_header(this);// 删除此句没影响
soap_body_begin_in(this);
dispatch();
13、修改soapC.cpp,在soap_out_SOAP_ENV__Header()、soap_in_SOAP_ENV__Header()两个函数中加入处理action的代码
SOAP_FMAC3 int SOAP_FMAC4soap_out_SOAP_ENV__Header(struct soap *soap, const char *tag, int id, conststruct SOAP_ENV__Header *a, const char *type)
(void)(void) (void) (void)
if(soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a,SOAP_TYPE_SOAP_ENV__Header), type))
return soap-&
if(soap_element_begin_out(soap, "Actionxmlns=\"/ws/2005/05/addressing/none\"",id, type)
|| soap_string_out(soap,soap-&action, 0)
|| soap_element_end_out(soap,"Action"))
return soap-&
returnsoap_element_end_out(soap, tag);
SOAP_FMAC3 struct SOAP_ENV__Header * SOAP_FMAC4 soap_in_SOAP_ENV__Header(structsoap *soap, const char *tag, struct SOAP_ENV__Header *a, const char *type)
if(soap_element_begin_in(soap, tag, 0, type))
return NULL;
soap_in_string(soap,"Action", &soap-&action, "xsd:string");
14、在使用客户端时,让soap-&header不为空,则可以加上header和action
m_pProxy = newBasicHttpBinding_USCOREIServiceProxy(SOAP_C_UTFSTRING);
m_pProxy-&header = new struct SOAP_ENV__Header();
步骤三:项目3使用接口
1、修改项目1,使项目1仅具有项目3作为客户端时的接口
2、项目3引用项目1的服务,此时,项目3具备了作为客户端的功能
3、修改项目1,使项目1仅具有项目3作为服务端时的接口
4、项目3获得项目1的IService.cs,Service.cs两个文件,并把项目1的app.config文件合并进项目3,此时,项目3具备了作为服务端的功能
5、实现over JMS,略。
步骤四:接口规则
1、项目1定义接口时,参数可以使用C#普通类型(int、char、double、float、string)、结构体、List
2、C#端定义string,可以用string str = ""; 不要用string str =
3、String类型赋值时要Base64 encode,得到时要Base64 decode
4、C++端接口如果是Request/Response模式,则有两个结构体参数,第一个是输入参数,第二个是输出参数;如果是OneWay模式,则有一个结构体参数。
5、C++端-Service类接口实现时,由于结构体参数内部大部分都为指针,而且如果用对象给输出参数赋值的话,经常会出现对象销毁而打包失败,故采取以下措施:
intBasicHttpBinding_USCOREIService1Service::ClientLogin(_ns1__ClientLogin *ns1__ClientLogin,_ns1__ClientLoginResponse *ns1__ClientLoginResponse)
// 防止多次泄露,这样只泄露一次的内存空间
static_ns1__ClientLoginResponse* pClientLoginResponse = NULL;
if(pClientLoginResponse != NULL)
deletepClientLoginResponse-&ClientLoginR
pClientLoginResponse-&ClientLoginResult = NULL;
deletepClientLoginResponse-&
pClientLoginResponse-&error = NULL;
deletepClientLoginResponse-&sessionId;
pClientLoginResponse-&sessionId = NULL;
delete pClientLoginR
pClientLoginResponse = NULL;
pClientLoginResponse = new _ns1__ClientLoginResponse();
pClientLoginResponse-&ClientLoginResult =
pClientLoginResponse-&error =
pClientLoginResponse-&sessionId =
// 防止多次泄露处理完毕
*ns1__ClientLoginResponse =*pClientLoginR
赋值时多采用【*指针 = *指针】的方式
&&&&推荐文章:
【上篇】【下篇】新手园地& & & 硬件问题Linux系统管理Linux网络问题Linux环境编程Linux桌面系统国产LinuxBSD& & & BSD文档中心AIX& & & 新手入门& & & AIX文档中心& & & 资源下载& & & Power高级应用& & & IBM存储AS400Solaris& & & Solaris文档中心HP-UX& & & HP文档中心SCO UNIX& & & SCO文档中心互操作专区IRIXTru64 UNIXMac OS X门户网站运维集群和高可用服务器应用监控和防护虚拟化技术架构设计行业应用和管理服务器及硬件技术& & & 服务器资源下载云计算& & & 云计算文档中心& & & 云计算业界& & & 云计算资源下载存储备份& & & 存储文档中心& & & 存储业界& & & 存储资源下载& & & Symantec技术交流区安全技术网络技术& & & 网络技术文档中心C/C++& & & GUI编程& & & Functional编程内核源码& & & 内核问题移动开发& & & 移动开发技术资料ShellPerlJava& & & Java文档中心PHP& & & php文档中心Python& & & Python文档中心RubyCPU与编译器嵌入式开发驱动开发Web开发VoIP开发技术MySQL& & & MySQL文档中心SybaseOraclePostgreSQLDB2Informix数据仓库与数据挖掘NoSQL技术IT业界新闻与评论IT职业生涯& & & 猎头招聘IT图书与评论& & & CU技术图书大系& & & Linux书友会二手交易下载共享Linux文档专区IT培训与认证& & & 培训交流& & & 认证培训清茶斋投资理财运动地带快乐数码摄影& & & 摄影器材& & & 摄影比赛专区IT爱车族旅游天下站务交流版主会议室博客SNS站务交流区CU活动专区& & & Power活动专区& & & 拍卖交流区频道交流区
丰衣足食, 积分 877, 距离下一级还需 123 积分
论坛徽章:0
本帖最后由 blue_sky 于
11:36 编辑
已通过客户端连接服务器生成开发需要的文件, 其中soapStub.h文件内容如下:
/* soapStub.h
& &Generated by gSOAP 2.7.17 from yzzx.h
& &Copyright(C) , Robert van Engelen, Genivia Inc. All Rights Reserved.
& &This part of the software is released under one of the following licenses:
& &GPL, the gSOAP public license, or Genivia's license for commercial use.
#ifndef soapStub_H
#define soapStub_H
#define SOAP_NAMESPACE_OF_ns1& &&http://tempuri.org/&
#include &stdsoap2.h&
#ifdef __cplusplus
extern &C& {
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Enumerations& && && && && && && && && && && && && && && && && && && && && &*
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Types with Custom Serializers& && && && && && && && && && && && && && && & *
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Classes and Structs& && && && && && && && && && && && && && && && && && &&&*
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
#if 0 /* volatile type: do not declare here, declared elsewhere */
#ifndef SOAP_TYPE__ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterface
#define SOAP_TYPE__ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterface (7)
/* ns1:YZZXService___YZZXInterface */
struct _ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterface
& && &&&char *AI /* required element of type xsd:string */
#ifndef SOAP_TYPE__ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterfaceResponse
#define SOAP_TYPE__ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterfaceResponse (8
/* ns1:YZZXService___YZZXInterfaceResponse */
struct _ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterfaceResponse
& && &&&char *R& &/* SOAP 1.2 RPC return element (when namespace qualified
) */& & /* required element of type xsd:string */
& && &&&char *AI /* required element of type xsd:string */
#ifndef SOAP_TYPE___ns1__YZZXInterface
#define SOAP_TYPE___ns1__YZZXInterface (12)
/* Operation wrapper: */
struct __ns1__YZZXInterface
& && &&&struct _ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterface *ns1__YZZXSer
vice_USCORE_USCORE_USCOREYZZXI /* optional element of type ns1:YZZXServ
ice___YZZXInterface */
#ifndef SOAP_TYPE_SOAP_ENV__Header
#define SOAP_TYPE_SOAP_ENV__Header (13)
/* SOAP Header: */
struct SOAP_ENV__Header
#ifdef WITH_NOEMPTYSTRUCT
& && &&&& &&&/* dummy member to enable compilation */
#ifndef SOAP_TYPE_SOAP_ENV__Code
#define SOAP_TYPE_SOAP_ENV__Code (14)
/* SOAP Fault Code: */
struct SOAP_ENV__Code
& && &&&char *SOAP_ENV__V&&/* optional element of type xsdName */
& && &&&struct SOAP_ENV__Code *SOAP_ENV__S& && & /* optional element of t
ype SOAP-ENV:Code */
#ifndef SOAP_TYPE_SOAP_ENV__Detail
#define SOAP_TYPE_SOAP_ENV__Detail (16)
/* SOAP-ENVetail */
struct SOAP_ENV__Detail
& && &&&int __& &&&/* any type of element &fault& (defined below) */
& && &&&void *& & /* transient */
& && &&&char *__
#ifndef SOAP_TYPE_SOAP_ENV__Reason
#define SOAP_TYPE_SOAP_ENV__Reason (19)
/* SOAP-ENV:Reason */
struct SOAP_ENV__Reason
& && &&&char *SOAP_ENV__T& &/* optional element of type xsd:string */
#ifndef SOAP_TYPE_SOAP_ENV__Fault
#define SOAP_TYPE_SOAP_ENV__Fault (20)
/* SOAP Fault: */
struct SOAP_ENV__Fault
& && &&&char *& && &&&/* optional element of type xsdName */
& && &&&char *& && &/* optional element of type xsd:string */
& && &&&char *& && & /* optional element of type xsd:string */
& && &&&struct SOAP_ENV__Detail *& && &&&/* optional element of type SOAP
-ENVetail */
& && &&&struct SOAP_ENV__Code *SOAP_ENV__C&&/* optional element of type SOAP
-ENV:Code */
& && &&&struct SOAP_ENV__Reason *SOAP_ENV__R& && &/* optional element of t
ype SOAP-ENV:Reason */
& && &&&char *SOAP_ENV__N& &/* optional element of type xsd:string */
& && &&&char *SOAP_ENV__R& &/* optional element of type xsd:string */
& && &&&struct SOAP_ENV__Detail *SOAP_ENV__D& && &/* optional element of t
ype SOAP-ENVetail */
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Typedefs& && && && && && && && && && && && && && && && && && && && && && & *
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
#ifndef SOAP_TYPE__QName
#define SOAP_TYPE__QName (5)
typedef char *_QN
#ifndef SOAP_TYPE__XML
#define SOAP_TYPE__XML (6)
typedef char *_XML;
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Externals& && && && && && && && && && && && && && && && && && && && && && &*
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Server-Side Operations& && && && && && && && && && && && && && && && && &&&*
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
SOAP_FMAC5 int SOAP_FMAC6 __ns1__YZZXInterface(struct soap*, struct _ns1__YZZXSe
rvice_USCORE_USCORE_USCOREYZZXInterface *ns1__YZZXService_USCORE_USCORE_USCOREYZ
ZXInterface, struct _ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterfaceResponse
*ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterfaceResponse);
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Server-Side Skeletons to Invoke Service Operations& && && && && && && && & *
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap*);
SOAP_FMAC5 int SOAP_FMAC6 soap_serve_request(struct soap*);
SOAP_FMAC5 int SOAP_FMAC6 soap_serve___ns1__YZZXInterface(struct soap*);
/******************************************************************************\
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
* Client-Side Call Stubs& && && && && && && && && && && && && && && && && &&&*
*& && && && && && && && && && && && && && && && && && && && && && && && && & *
\******************************************************************************/
SOAP_FMAC5 int SOAP_FMAC6 soap_call___ns1__YZZXInterface(struct soap *soap, cons
t char *soap_endpoint, const char *soap_action, struct _ns1__YZZXService_USCORE_
USCORE_USCOREYZZXInterface *ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterface,
struct _ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterfaceResponse *ns1__YZZXSer
vice_USCORE_USCORE_USCOREYZZXInterfaceResponse);
#ifdef __cplusplus
/* End of soapStub.h */
我在客户端开发的代码如下:
int CustomServ( char *Reqbuf, char *Repbuf)
& && &&&char& &buffer[1024];
& && &&&struct _ns1__YZZXService_USCORE_USCORE_USCOREYZZXI
& && &&&struct _ns1__YZZXService_USCORE_USCORE_USCOREYZZXInterfaceR
& && &&&memset(&czjrepdata, 0, sizeof(czjrepdata));
& && &&&memset(&czjreqdata, 0, sizeof(czjreqdata));
& && &&&memset(buffer, 0, sizeof(buffer));
& && &&&strcpy(buffer, Reqbuf);
& && &&&czjreqdata.AInvoice=
& && &&&soap_init1(&soap, SOAP_XML_INDENT);
& && &&&soap_call___ns1__YZZXInterface(&soap, server, &&, &czjreqdata, &czjrepdata);
& && &&&if (soap.error)
& && && && && & soap_print_fault(&soap, stderr);
& && && && && & return -1;
& && &&&strcpy(Repbuf, czjrepdata.AInvoice);
& && &&&soap_destroy(&soap);
& && &&&soap_end(&soap);
& && &&&soap_done(&soap);
& && &&&return 0;
请教高手,我的程序调用是否正确,先谢谢了!
&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp
丰衣足食, 积分 877, 距离下一级还需 123 积分
论坛徽章:0
WEB&&req.xml 文件如下:
&?xml version=&1.0& encoding=&UTF-8&?&
&SOAP-ENV:Envelope
xmlns:SOAP-ENV=&http://schemas.xmlsoap.org/soap/envelope/&
xmlns:SOAP-ENC=&http://schemas.xmlsoap.org/soap/encoding/&
xmlnssi=&http://www.w3.org/2001/XMLSchema-instance&
xmlnssd=&http://www.w3.org/2001/XMLSchema&
xmlns:ns1=&http://tempuri.org/&&
&SOAP-ENV:Body&
& &&ns1:YZZXService___YZZXInterface&
& & &ns1:AInvoice&&/ns1:AInvoice&
& &&/ns1:YZZXService___YZZXInterface&
&/SOAP-ENV:Body&
&/SOAP-ENV:Envelope&
丰衣足食, 积分 877, 距离下一级还需 123 积分
论坛徽章:0
我在windows下用fiddler工具,模拟向服务端发送出http报文,返回是正确的,可是用我的程序测试,返回的就不对了,还是乱码。我想问一下,我是需要进行编码设置与转换呢还是我的程序有问题呢?
自己顶一下,在线等高手解答
富足长乐, 积分 5144, 距离下一级还需 2856 积分
论坛徽章:1
丰衣足食, 积分 877, 距离下一级还需 123 积分
论坛徽章:0
问题已解决!
丰衣足食, 积分 826, 距离下一级还需 174 积分
论坛徽章:1
LZ应该把自己的解决方法贴出来,而不是一句“已解决“。&&因为别人也可能遇到你这样的问题,如果看到你这一句“已解决“估计都要拍桌子了。&&来问问题的也要有共享的精神。
富足长乐, 积分 5144, 距离下一级还需 2856 积分
论坛徽章:1
LS说的是。
稍有积蓄, 积分 249, 距离下一级还需 251 积分
论坛徽章:0
鄙视一下,继续等待。
白手起家, 积分 2, 距离下一级还需 198 积分
论坛徽章:0
真的挺鄙视这样结贴

我要回帖

更多关于 archaius core maven 的文章

 

随机推荐