C++调用java基于XFire的WebService接口
2014-04-04 16:41
501 查看
1、修改soapStub.h文件的结构体SOAP_ENV__Header
2、修改soapC.cpp文件
在namespaces中添加{"wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", NULL, NULL}
4、调用接口
注:若是https://的接口,需要key,可加上下面几句:
在调试时可通过Wireshark进行抓包分析,客户端发送的xml格式为:
服务端返回值
/* SOAP Header: */ struct SOAP_ENV__Header { #ifdef WITH_NOEMPTYSTRUCT private: char dummy; /* dummy member to enable compilation */ public: int mustUnderstand; char *wsse__username; char *wsse__password; SOAP_ENV__Header(void) { mustUnderstand = 1; wsse__username = "username"; wsse__password = ""; } #endif };
2、修改soapC.cpp文件
SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV__Header(struct soap *soap, const char *tag, int id, const struct SOAP_ENV__Header *a, const char *type) { /*(void)soap; (void)tag; (void)id; (void)type; if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_SOAP_ENV__Header), type)) return soap->error; return soap_element_end_out(soap, tag);*/ (void)soap; (void)tag; (void)id; (void)type; if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_SOAP_ENV__Header), type)) return soap->error; if (soap_element_begin_out(soap, "wsse:Security", -1, "") || soap_element_begin_out(soap, "wsse:UsernameToken", -1, "") || soap_out_string(soap, "wsse:Username", -1, &a->wsse__username, "") || soap_out_string(soap, "wsse:Password", -1, &a->wsse__password, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText") || soap_element_end_out(soap, "wsse:UsernameToken") || soap_element_end_out(soap, "wsse:Security") ) return soap->error; soap->mustUnderstand = 1; return soap_element_end_out(soap, tag); }
// 此处,若返回文件无需Header头验证,可不修改 SOAP_FMAC3 struct SOAP_ENV__Header * SOAP_FMAC4 soap_in_SOAP_ENV__Header(struct soap *soap, const char *tag, struct SOAP_ENV__Header *a, const char *type) { struct SOAP_ENV__Header header; header.wsse__username = "IUTEIt1Frec="; soap->header = &header; soap->mustUnderstand = 1; if (soap_element_begin_in(soap, tag, 0, type)) return NULL; a = (struct SOAP_ENV__Header *)soap_id_enter(soap, soap->id, a, SOAP_TYPE_SOAP_ENV__Header, sizeof(struct SOAP_ENV__Header), 0, NULL, NULL, NULL); if (!a) return NULL; soap_default_SOAP_ENV__Header(soap, a); size_t soap_flag_wsse__security = 1; if (soap->body && !*soap->href) { for (;;) { if ( soap_flag_wsse__security ) { if ( soap_element_begin_in(soap, NULL, 0, NULL) ) return NULL; if ( soap_element_begin_in(soap, NULL, 0, NULL) ) return NULL; if ( soap_in_string(soap, "", &a->wsse__username, "") && soap_in_string(soap, "", &a->wsse__password, "") ) { soap_flag_wsse__security--; soap_element_end_in(soap, NULL); soap_element_end_in(soap, NULL); } } soap->error = SOAP_TAG_MISMATCH; if (soap->error == SOAP_TAG_MISMATCH) soap->error = soap_ignore_element(soap); if (soap->error == SOAP_NO_TAG) break; if (soap->error) return NULL; } if (soap_element_end_in(soap, tag)) return NULL; } else { a = (struct SOAP_ENV__Header *)soap_id_forward(soap, soap->href, (void*)a, 0, SOAP_TYPE_SOAP_ENV__Header, 0, sizeof(struct SOAP_ENV__Header), 0, NULL); if (soap->body && soap_element_end_in(soap, tag)) return NULL; } return a; }3、修改NetImageServiceHttpBindingProxy.cpp文件
void NetImageServiceHttpBindingProxy::NetImageServiceHttpBindingProxy_init(soap_mode imode, soap_mode omode) { soap_imode(this->soap, imode); soap_omode(this->soap, omode); soap_endpoint = NULL; static const struct Namespace namespaces[] = { {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL}, {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding", NULL}, {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL}, {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL}, {"ns1", "http://service.meiah.com", NULL, NULL}, {"ns2", "http://po.meiah.com", NULL, NULL}, {"ns3", "http://pojo.sys.meiya.com", NULL, NULL}, {"ns4", "http://pojo.forensics.meiya.com", NULL, NULL}, {"ns5", "http://pojo.clue.meiya.com", NULL, NULL}, {"wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", NULL, NULL}, {NULL, NULL, NULL, NULL} }; soap_set_namespaces(this->soap, namespaces); }
在namespaces中添加{"wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", NULL, NULL}
4、调用接口
struct SOAP_ENV__Header header; header.wsse__username = "IUTEIt1Frec="; header.wsse__password = ""; NetImageServiceHttpBindingProxy::soap->header = &header; soap_set_mode(NetImageServiceHttpBindingProxy::soap, SOAP_C_UTFSTRING); // 中文乱码问题 int nRet = NetImageServiceHttpBindingProxy::checkUser(&input, &output);
注:若是https://的接口,需要key,可加上下面几句:
NetImageServiceHttpBindingProxy::soap->ssl_flags = SOAP_SSL_NO_AUTHENTICATION; NetImageServiceHttpBindingProxy::soap->keyfile = "cert.pem"; NetImageServiceHttpBindingProxy::soap->password = "123456"; // 看需要
在调试时可通过Wireshark进行抓包分析,客户端发送的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/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://po.meiah.com" xmlns:ns3="http://pojo.sys.meiya.com" xmlns:ns4="http://pojo.forensics.meiya.com" xmlns:ns5="http://pojo.clue.meiya.com" xmlns:ns1="http://service.meiah.com"> <SOAP-ENV:Header> <wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <UsernameToken> <Username>IUTEIt1Frec=</Username> </UsernameToken> </wsse:Security> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:checkUser> <ns1:in0> <ns3:password></ns3:password> <ns3:username></ns3:username> </ns1:in0> </ns1:checkUser> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
服务端返回值
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <ns1:checkUserResponse> <ns1:out>验证成功</ns1:out> </ns1:checkUserResponse> </soap:Body> </soap:Envelope>
相关文章推荐
- 用xfire实现基于java的webservice接口调用
- Java使用XFire调用WebService接口
- java 调用 webService Xfire接口,xml解析为object
- C++通过gsoap做WebService接口 供C++及java客户端调用
- Java使用XFire调用WebService接口
- java 编写webservice 接口(xfire) ,调用webservice接口
- Java调用C++webservice接口
- java 调用webservice接口(wsdl)
- java调用webservice接口 几种方法
- 用java调用webservice接口
- Java程序员从笨鸟到菜鸟之(一百零九)一步一步学习webservice(三)开发第一个基于XFire的webservice
- Java调用webservice接口方法
- java中调用C/C++编写的生成的动态连接库dll文件接口的简单例子
- xFire实现Java间自定义类型的WebService调用(二)
- window下利用JNI在java代码中调用c/c++接口
- 使用java的xfire调用.net的webservice-王亮
- 基于JAVA的黄金数据接口调用代码实例
- java程序调用xfire发布的webService服务
- 使用Java-UrlConnection调用webService接口