Main BLOGGER
Google
WWW THIS BLOG
Saturday, March 25, 2006
 
gsoap DOM and xsd:anyType
1. In gSoap, xsd:anyType is of type soap_dom_element
2. with gSoap compiler, it is easy to do (de)serialization on C/C++ data structure
--a. set input flag of SOAP to SOAP_DOM_NODE
soap_set_imode(&soap, SOAP_DOM_NODE);
--b. declare the C/C++ data structure in the header file which will be processed by gSoap compiler soapcpp2
typedef float xsd__float;
c. write code to generate the element

int mcws__invokeCode(struct soap* , char *name,
struct mcws__invokeCodeResponse &result)
{
result.ret = 10;
struct soap soap;
soap_init(&soap);
soap_set_imode(&soap, SOAP_DOM_NODE);
xsd__float f = 12.34;
//xsd__float type is available, and the xsi:type attribute is present
//or element tag matches the type name
soap_dom_element retVal(&soap, NULL, "float", &f, SOAP_TYPE_xsd__float);
result.value = retVal;
cout << retVal;
return SOAP_OK;
}

struct mcws__invokeCodeResponse {
xsd__anyType value;
int ret;
};

--c. On the other end,we also need to tell gSoap

soap_set_imode(&soap, SOAP_DOM_NODE);
//let gSOAP do C/C++ serialization/de-serialization
struct mcws__invokeCodeResponse retVal;
xsd__float f;
char* name="eval";

if (soap_call_mcws__invokeCode(&soap,
"http://localhost:20065",
NULL, name, retVal) == SOAP_OK)
{
soap_dom_iterator walker=retVal.value.find(SOAP_TYPE_xsd__float);
for (;walker!=retVal.value.end();++walker)
{
//gSOAP will do the magic here
f = *((xsd__float*)(*walker).node);
}

}



<< Home

Powered by Blogger

Google
WWW THIS BLOG