作者:繁华落尽的星空 | 来源:互联网 | 2023-08-27 21:47
gSoap客户端通过SoapBindingProxy调用webservice服务端的时候,跟踪代码发现每次调用完一个接口后,都要调用soap_closesock(soap),有没有方法不soap_c
gSoap客户端通过SoapBindingProxy调用 webservice服务端的时候,跟踪代码发现每次调用完一个接口后,都要调用soap_closesock(soap),有没有方法不soap_closesock(soap),也就是保持长连接状态。
14 个解决方案
这个就比较麻烦了,我的服务程序是用Java封装的有状态Bean,连接后需要维持一个登录状态,才能获取到数据,否则是获取不到数据的,这样做也是为了减少服务器的开销。
我用delphi开发的webservice可以正常调用数据。
但是换成MFC的gSoap就成了这个样子。
实在不行的最后方法就是调用 delphi封装的DLL来获取数据。不过目前不想用这个方法!!!
既然有的gSoap,总得研究明白。
又跟踪下服务器代码,感觉gSoap每次连接的时候把一些东西给清空了,导致服务器端无法根据这部分信息来获取这个有状态Bean。
Delphi的Soap客户端可以。Java的Soap客户端也可以。
.Net还没有测试,估计应该也可以。
看来gSoap存在缺陷。(比较致命)
19.11 TCP and HTTP Keep-Alive
gSOAP supports keep-alive socket connections. To activate keep-alive support, set the SOAP_IO_KEEPALIVE flag for both input and output modes, see Section 9.12. For example
struct soap soap;
soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
19.11 TCP and HTTP Keep-Alive
回复5楼,我测试了,还是不行,之前我把各种输入、出的模式都测试过。
void CTestWebserviceDlg::OnButton3()
{
std::wstring str;
int i1=11;
int &i=mm;
std::wstring usr;
struct ns14__userLoginResponse _param_2;
ExpressLoginControlSoapBindingProxy Pgs("http://192.168.1.51:8080/");
Pgs.ExpressLoginControlSoapBindingProxy_init(SOAP_IO_KEEPALIVE,SOAP_IO_KEEPALIVE);
try{
CString s3;
Pgs.userLogin(DecodeUtf8("00003_BSWH"),DecodeUtf8("123456"),_param_2);//需要靠这个登陆维持session状态
CString ll;
int back=Pgs.getAllAccountCount(i);
CString str2;
str2.Format("%d",i);
MessageBox("getAllAccountCount:"+str2);
//delete Pgs;
}
catch(...){
MessageBox("连接失败");
}
}
代码如上。
就象我之前说的感觉是一些session里的东西给清了,导致的服务器不识别这个session了。
19.28 Client-Side COOKIE Support
Client-side COOKIE support is optional. To enable COOKIE support, compile all sources with option -DWITH_COOKIES, for example:
> c++ -DWITH_COOKIES -o myclient stdsoap2.cpp soapC.cpp soapClient.cpp
or add the following line to stdsoap.h:
#define WITH_COOKIES
Client-side COOKIE support is fully automatic. So just (re)compile stdsoap2.cpp with -DWITH_COOKIES to enable COOKIE-based session control in your client.
A database of COOKIEs is kept and returned to the appropriate servers. COOKIEs are not automatically saved to a file by a client. An example COOKIE file manager is included as an extras in the distribution. You should explicitly remove all COOKIEs before terminating a gSOAP context by calling soap_free_COOKIEs(soap) or by calling soap_done(soap).
To avoid "COOKIE storms" caused by malicious servers that return an unreasonable amount of COOKIEs, gSOAP clients/servers are restricted to a database size that the user can limit (32 COOKIEs by default), for example:
struct soap soap;
soap_init(&soap);
soap.COOKIE_max = 10;
请问楼主解决了吗? 给个答案,我也有这方面的问题。。。感谢。
to 10楼
我的方法就是不用 gSoap了,用delphi封装了一下。绝对好用!!!
我按照9楼的方法试验了,增加了一个宏在stdsoap2.h中,然后重新编译运行我的程序,依然不行。
下边是测试代码:
void CTestWebserviceDlg::OnButton3()
{
std::wstring str;
int i1=11;
std::wstring usr;
struct ns14__userLoginResponse _param_2;
ExpressLoginControlSoapBindingProxy Pgs("http://127.0.0.1:8085/lcws/services/ExpressLoginControl",SOAP_IO_KEEPALIVE);
Pgs.COOKIE_max=10;
try{
CString s3;
Pgs.userLogin(DecodeUtf8("BSWH"),DecodeUtf8("123456"),_param_2);
CString ll;
int back=0;
back=Pgs.getAllAccountCount(i1);//正常i应该是返回的数量,现在依然是0
CString str2;
str2.Format("%d",i);
MessageBox("getAllAccountCount:"+str2);
}
catch(...){
MessageBox("连接失败");
}
}
楼主啊,问题解决了么?求联系方式,有问题想请教请教
在*Proxy.h里,构造函数里,soap = soap_new()后面添加
soap_init2( soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
和
soap->send_timeout = 45;
soap->recv_timeout = 45;
soap->connect_timeout = 100;
soap->accept_timeout = 10;
应该可以解决吧?我就是这么做的