From: Thomas H. <pol...@us...> - 2006-02-12 19:07:25
|
Update of /cvsroot/smartwin/SmartWin/SmartSOAP/Tester1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16765/SmartSOAP/Tester1 Modified Files: Main.cpp Log Message: Index: Main.cpp =================================================================== RCS file: /cvsroot/smartwin/SmartWin/SmartSOAP/Tester1/Main.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Main.cpp 12 Feb 2006 16:20:08 -0000 1.7 +++ Main.cpp 12 Feb 2006 19:07:09 -0000 1.8 @@ -175,6 +175,97 @@ return returnFromServer.returnedStrings; } +class TestReturnStuffContents +{ +public: + string stringValue; +}; + +class TestReturnStuff +{ +public: + int intValue; + string stringValue; + double decimalValue; + vector<TestReturnStuffContents> arrayOfContents; +}; + +class TestGetStuff +{ +public: + string getStuffString; +}; + +class GetCustomObjectSerializer +{ +public: + string serialize( const TestGetStuff & sender ) + { + // We're using the SmartXML classes to serialize our request + XmlNode rootNode( "Envelope", "soap" ); + rootNode.addNamespace( XmlNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi" ) ); + rootNode.addNamespace( XmlNamespace( "http://www.w3.org/2001/XMLSchema", "xsd" ) ); + rootNode.addNamespace( XmlNamespace( "http://schemas.xmlsoap.org/soap/envelope/", "soap" ) ); + + XmlNode & bodyNode = rootNode.insertNode( "Body", "soap" ); + + XmlNode & helloWorldNode = bodyNode.insertNode( "GetCustomObject" ); + helloWorldNode.addNamespace( XmlNamespace( "http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject" ) ); + XmlNode & getStuffNode = helloWorldNode.insertNode( "getStuff" ); + getStuffNode.insertNode( "getStuffString", sender.getStuffString, "" ); + XmlDocument doc( rootNode ); + stringstream strStream; + strStream << doc; + std::string retVal = strStream.str(); + return retVal; + } + + TestReturnStuff deserialize( istream & stream ) + { + TestReturnStuff retVal; + + // We're using the SmartXML to deserialize our response + XmlDocument document( stream ); + retVal.intValue = boost::lexical_cast<int>( document.getDocumentNode()[0][0][0][0].getContent() ); + retVal.stringValue = document.getDocumentNode()[0][0][0][1].getContent(); + retVal.decimalValue = boost::lexical_cast<double>( document.getDocumentNode()[0][0][0][2].getContent() ); + for( std::vector<XmlNode>::const_iterator stringIter = document.getDocumentNode()[0][0][0][3].childrenBegin(); + stringIter != document.getDocumentNode()[0][0][0][3].childrenEnd(); + ++stringIter ) + { + TestReturnStuffContents tmp; + tmp.stringValue = (*stringIter)[0].getContent(); + retVal.arrayOfContents.push_back( tmp ); + } + return retVal; + } +}; + +TestReturnStuff getCustomObject( const TestGetStuff & getStuff ) +{ + // Then we must have a Serializer for serializing the Request and deserializing the Response + GetCustomObjectSerializer serializer; + + // Then we create our SoapRequest + SoapRequest<GetCustomObjectSerializer, TestGetStuff, TestReturnStuff> soap( + "localhost", + "/Tester1Endpoint/CustomObjects.asmx", + "SOAPAction: \"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/GetCustomObject\"", + 80, + serializer, + getStuff + ); + + // Then we send the Request (or call the WebService function) and gets a SoapResponse back + SoapResponse<GetCustomObjectSerializer, TestGetStuff, TestReturnStuff> response = soap.send(); + + // Now our SoapResponse will contain a HelloWorldReturnValue which we can retrieve + TestReturnStuff returnFromServer = response.getReturnValue(); + + // Now returning the returning string from our WebService + return returnFromServer; +} + int main() { cout << "Calling our WebService with the value of: 2" << endl; @@ -206,6 +297,19 @@ cout << "\t\t" << *idxIter << endl; } + cout << endl << endl << "Then we're call a function taking a custom object returning another custom object" << endl; + TestGetStuff getStuff; + getStuff.getStuffString = "Tjobing"; + TestReturnStuff returnStuff = getCustomObject( getStuff ); + cout << "Return value was: " << endl; + cout << returnStuff.intValue << endl << returnStuff.stringValue << endl << returnStuff.decimalValue << endl; + for( std::vector<TestReturnStuffContents>::const_iterator iter = returnStuff.arrayOfContents.begin(); + iter != returnStuff.arrayOfContents.end(); + ++iter ) + { + cout << "\t\t" << iter->stringValue << endl; + } + string g; cin >> g; |