2013-10-07 21 views
1

我需要將我的跨平臺程序連接到SOAP Web服務。我編譯了gSOAP工具wsdl2h和soapcpp2,並使用這些工具生成了來自.wsdl文件的源代碼文件。我在stdsoap2.h中定義了「#define WITH_OPENSSL」,並以這種方式使用了SSL。問題是,當我打電話給該服務的電話返回錯誤30,這意味着SSL錯誤,但我不知道什麼是真正的問題。我知道服務器發送自簽名證書,因爲這是一個測試環境。確實打印出與此相關的錯誤消息。輸出是:gSOAP - 如何使用SSL和自簽名證書

Creating SOAP objects ... 
Calling SOAP httpAccessService: 
SSL verify error or warning with certificate at depth 0: self signed certificate 
certificate issuer /C=IT/ST=Milan/L=Milan/O=Company/OU=Company/CN=company.it 
certificate subject /C=IT/ST=Milan/L=Milan/O=Company/OU=Company/CN=company.it 
SOAP ERROR 30 

我使用調用服務的功能是這樣的:

空隙gSOAPTesting ::的runTest() { INT結果= 0; size_t requestSize; size_t responseSize;

char endpoint[1024]; 
char buffer[8192]; 

string SoapAction; 
struct soap *soap_container; 

ApplicationConfigurationServiceSoapBindingProxy Proxy1; 

_ns1__httpAccessService *httpAccessService; 
_ns1__httpAccessServiceResponse *httpAccessServiceResponse; 

printf("Creating SOAP objects ...\n"); 
soap_container = soap_new(); 
//soap_container->mode 
httpAccessService = (_ns1__httpAccessService *) soap_instantiate(soap_container , SOAP_TYPE___ns1__httpAccessService , "" , "" , &requestSize); 
httpAccessServiceResponse = (_ns1__httpAccessServiceResponse *) soap_instantiate(soap_container , SOAP_TYPE___ns1__httpAccessService , "" , "" , &responseSize); 

soap_ssl_init(); /* init OpenSSL (just once) */ 

if(soap_ssl_client_context(soap_container , 
SOAP_SSL_DEFAULT , 
NULL, 
NULL, 
NULL, 
NULL, 
NULL  
) != SOAP_OK) 
{ 
    printf("SOAP SSL Initialization Failure\n"); 
    soap_print_fault(soap_container , stderr); 
    return ; 
} 

printf("Calling SOAP httpAccessService:\n"); 

SoapAction.clear(); 
SoapAction.append(SOAP_NAMESPACE_OF_ns1); 
SoapAction.append("/"); 
SoapAction.append("httpAccessService");  

result = Proxy1.httpAccessService("https://XXX.XXX.XXX.XXX:XXXX" , NULL , httpAccessService , httpAccessServiceResponse); 

if(result == SOAP_OK) 
{ 
    printf("SOAP OK\n");       
} 
else 
{ 
    printf("SOAP ERROR %d\n" , result); 

    if(soap_check_state(soap_container)) printf("Error: request soap struct not initialized\n"); 

    if(httpAccessService->soap == NULL) 
    { 
     printf("Error: NULL request SOAP struct\n"); 
     return;       
    } 

    if(httpAccessService->soap->endpoint == NULL) printf("Error: Empty request endpoint\n"); 

    soap_stream_fault(soap_container , std::cout);   
}  

}

任何幫助表示讚賞。

回答

1

問題與不可信的證書有關,因爲它是自簽名的。如果我在stdsoap2.cpp ...

if (!ok) 
{ soap_set_sender_error(soap, "SSL/TLS error", "SSL/TLS certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR); 
    soap->fclosesocket(soap, sk); 
    return SOAP_INVALID_SOCKET; 
} 

評論這些行......如果它是由一個未知的機構頒發的證書,甚至接受。

0

如果(soap_ssl_client_context(&肥皂, SOAP_SSL_NO_AUTHENTICATION, NULL,NULL, NULL,/ * ```````````````````````````````` */ NULL,NULL)!= SOAP_OK) {

如果你都OK忽略主機你可以做類似上面的事情,而不是在生成的文件中傳遞東西