问题描述
使用Gsoap访问IIS Web服务。 我有与this link中类似的错误,表明该错误已通过-lssl编译解决。
我在构建中所做的与
相同g++ -o client client.cpp stdsoap2.cpp soapC.cpp soapDataManagementSoapProxy.cpp -I /usr/local/ssl/include -L/home/xavier/GSOAP/lib -lgsoapssL++ -L/usr/local/ssl/lib -lssl
我的GSOAP库是使用OpenSSL构建的。
但是我仍然有错误
SOAP 1.2 fault SOAP-ENV:Sender[no subcode]
"OpenSSL not installed: recompile with -DWITH_OPENSSL"
Detail: [no detail]
我的测试代码如下。怎么了?
#include "soapDataManagementSoapProxy.h"
#include "DataManagementSoap.nsmap"
const char server[] = "https://XXXXXXX.com/XXXmanagement.asmx";
int main(int argc,char **argv)
{
DataManagementSoapProxy webinf;
webinf@R_502_6407@ap_endpoint = server;
_tempuri__ReadTestData* a;
_tempuri__ReadTestDataResponse res;
int ret = webinf.ReadTestData(a,res);
if (webinf.error){
webinf@R_502_6407@ap_stream_fault(std::cerr);
}
else{
//printf("result = %g\n",result);
std::cout << "Success " << std::endl;
}
webinf.destroy(); /* clean up mem */
return 0;
}
解决方法
此问题的解决方案是
#include "calc.nsmap"
#include "soapcalcProxy.h" // generated with soapcpp2 -j calc.h
calcProxy calc("https-server-endpoint-URL");
double sum;
soap_ssl_init(); // init SSL (just need to do this once in an application)
// soap_ssl_no_init(); // or prevent init OpenSSL when already initialized elsewhere in an application
if (soap_ssl_client_context(calc.soap,SOAP_SSL_DEFAULT,NULL,// no keyfile
NULL,// no keyfile password
"cacerts.pem",// trusted certificates (or use self-signed cacert.pem)
NULL,// no capath to trusted certificates
NULL // no random data to seed randomness
))
{
calc.soap_stream_fault(std::cerr);
exit(EXIT_FAILURE);
}
if (calc.add(1.23,4.56,sum) == SOAP_OK)