Hi All, Here I am facing a strange behavior with soap_sender_fault.
When the server sends an error message to the client using "soap_sender_fault", then the client is not getting the message proparly if the error code has the XML data like, soap_sender_fault(soap, "Square root of negative value", "< errorcode xmlns='http://tempuri.org'> 123 < /errorcode > < errorinfo xmlns='http://tempuri.org' > abc < /errorinfo >"); The client should get the following message in "soap->fault->detail->__any" field: < errorcode xmlns='http://tempuri.org'> 123 < /errorcode > < errorinfo xmlns='http://tempuri.org' > abc < /errorinfo > But strangely, the client is getting only the first tag like. < errorcode xmlns='http://tempuri.org'> 123 < /errorcode >. I observed that I am able to the entire xml string coming from the server by using the Wireshark/tcpmon. That means the server is sending the entire xml string. But the gsoap client fiails to parse the received string properly. I also observed that if we use a root tag for the entire xml, it is working as expected. But according to the SOAP design, I should get the entire xml string without using the root tag. So it seems to be there may be a problem with gsoap implementation itself. Can anyone please help me out in resoving this problem. Quick response is appriciated. The below is an example to depict the above problem. This is a claculator example. The soapserver returns the xml string having the errorcode and errorinfo tags when the soap client is trying to attempt a square root of -ve number. calc.h ====== // Contents of file "calc.h": //gsoap ns service name: calculator //gsoap ns service style: rpc //gsoap ns service encoding: encoded //gsoap ns service port: http://mydomain/path/calculator.cgi //gsoap ns service namespace: urn:calculator int ns__add(double a, double b, double &result); int ns__sub(double a, double b, double &result); int ns__sqrt(double a, double &result); calcServer.cpp ============== #include "soapH.h" #include "calculator.nsmap" int main() { struct soap soap; int m, s; // master and slave sockets soap_init(&soap); m = soap_bind(&soap, "localhost", 8008, 100); if (m < 0) soap_print_fault(&soap, stderr); else { fprintf(stderr, "Socket connection successful: master socket = %d\n", m); for (int i = 1; ; i++) { s = soap_accept(&soap); if (s < 0) { soap_print_fault(&soap, stderr); break; } // fprintf(stderr, "%d: accepted connection from IP=%d.%d.%d..%d socket=%d", i,(soap.ip>>24)&0xFF, (soap.ip>>16)&0xFF, (soap.ip>>8)&0xFF, soap.ip&0xFF, s); if (soap_serve(&soap) != SOAP_OK) soap_print_fault(&soap, stderr); fprintf(stderr, "request served\n"); soap_destroy(&soap); soap_end(&soap); } } soap_done(&soap); // close master socket and detach environment } // Implementation of the "add" remote method: int ns__add(struct soap *soap, double a, double b, double &result) { result = a + b; return SOAP_OK; } // Implementation of the "sub" remote method: int ns__sub(struct soap *soap, double a, double b, double &result) { result = a - b; return SOAP_OK; } // Implementation of the "sqrt" remote method: int ns__sqrt(struct soap *soap, double a, double &result) { if (a >= 0) { result = sqrt(a); return SOAP_OK; } else { return soap_sender_fault(soap, "Square root of negative value", "< errorcode xmlns='http://tempuri.org'> 123 < /errorcode >< errorinfo xmlns='http://tempuri.org' > abc < /errorinfo >"); } } calcClient.cpp ============== #include "calculator.nsmap" #include "soapcalculatorProxy.h" #include <stdio.h> int main() { calculator myObj; struct soap *mySoapObj = soap_new(); myObj.soap = mySoapObj; myObj.endpoint = "http://localhost:8008"; double var=0; if(myObj.ns__sqrt(-1,var)==SOAP_OK) { printf("%f",var); return true; } else { // required to get entire xml string printf ("%s\n", myObj.soap->fault->detail->__any); } return false; } Output: ------- < errorcode xmlns='http://tempuri.org'> 123 < /errorcode > Thanks, Pavan
