|
From: andrew7 <bd...@us...> - 2006-11-30 00:44:59
|
Update of /cvsroot/smartwin/SmartWin/SmartSOAP/Tester1 In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv22406/SmartSOAP/Tester1 Modified Files: Main.cpp Log Message: Unicode support Index: Main.cpp =================================================================== RCS file: /cvsroot/smartwin/SmartWin/SmartSOAP/Tester1/Main.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- Main.cpp 3 Sep 2006 15:25:24 -0000 1.14 +++ Main.cpp 30 Nov 2006 00:44:55 -0000 1.15 @@ -17,7 +17,7 @@ class HelloWorldReturnValue { public: - string helloWorldString; + tstring helloWorldString; }; // This is the object being "sent" to the HelloWorld function @@ -30,20 +30,20 @@ class HelloWorldSerializer { public: - string serialize( const HelloWorldSender & sender ) + tstring serialize( const HelloWorldSender & sender ) { // We're using the SmartXML classes to serialize our request, but we strictly speaking don't have to do so! - XmlDocument doc( "Envelope", "", "soap" ); + XmlDocument doc( _T("Envelope"), _T(""), _T("soap") ); XmlNode & rootNode = ( * doc.getDocumentNode() ); - 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" ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema-instance"), _T("xsi") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema"), _T("xsd") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://schemas.xmlsoap.org/soap/envelope/"), _T("soap") ) ); - XmlNode & bodyNode = rootNode.addChild( "Body", "", "soap" ); + XmlNode & bodyNode = rootNode.addChild( _T("Body"), _T(""), _T("soap") ); - XmlNode & helloWorldNode = bodyNode.addChild( "HelloWorld", "", "" ); - helloWorldNode.addNamespace( XmlNamespace( "http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject" ) ); - helloWorldNode.addChild( "number", boost::lexical_cast< string >( sender.intValue ), "" ); + XmlNode & helloWorldNode = bodyNode.addChild( _T("HelloWorld"), _T(""), _T("") ); + helloWorldNode.addNamespace( XmlNamespace( _T("http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject") ) ); + helloWorldNode.addChild( _T("number"), boost::lexical_cast< tstring >( sender.intValue ), _T("") ); return doc.toString(); } @@ -59,7 +59,7 @@ // This is a "Proxy Function" which will call our HelloWorld WebService function abstracting away all the details of the WebService. // You don't actually NEED one of these, but the code will be much easier to understand if you DO! -string helloWorld( int number ) +tstring helloWorld( int number ) { // First we create a HelloWorldSender which will be passed onto the WebService HelloWorld function HelloWorldSender sender; @@ -71,8 +71,8 @@ // Then we create our SoapRequest SoapRequest< HelloWorldSerializer, HelloWorldSender, HelloWorldReturnValue > soap( "localhost", // Which host is our WebService located at - "/Tester1Endpoint/CustomObjects.asmx", // What is the PATH to our WebService - "SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/HelloWorld\"", // What is the SOAPAction or basically the NAMESPACE of our WebService + the name of the function we're calling + _T("/Tester1Endpoint/CustomObjects.asmx"), // What is the PATH to our WebService + _T("SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/HelloWorld\""), // What is the SOAPAction or basically the NAMESPACE of our WebService + the name of the function we're calling 80, // Which TCP/IP port is the WebService listening on serializer, // The serializer/deserializer for our WebService call sender // The object we actually want to send @@ -92,33 +92,33 @@ { public: int howMany; - std::string whatShouldTheyContain; + tstring whatShouldTheyContain; }; class GetArrayOfStringsReturnValue { public: - vector< string > returnedStrings; + vector< tstring > returnedStrings; }; class GetArrayOfStringsSerializer { public: - string serialize( const GetArrayOfStringsSender & sender ) + tstring serialize( const GetArrayOfStringsSender & sender ) { // We're using the SmartXML classes to serialize our request - XmlDocument doc( "Envelope", "", "soap" ); + XmlDocument doc( _T("Envelope"), _T(""), _T("soap") ); XmlNode & rootNode = ( * doc.getDocumentNode() ); - 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" ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema-instance"), _T("xsi") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema"), _T("xsd") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://schemas.xmlsoap.org/soap/envelope/"), _T("soap") ) ); - XmlNode & bodyNode = rootNode.addChild( "Body", "", "soap" ); + XmlNode & bodyNode = rootNode.addChild( _T("Body"), _T(""), _T("soap") ); - XmlNode & helloWorldNode = bodyNode.addChild( "GetArrayOfStrings", "", "" ); - helloWorldNode.addNamespace( XmlNamespace( "http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject" ) ); - helloWorldNode.addChild( "howMany", boost::lexical_cast< string >( sender.howMany ), "" ); - helloWorldNode.addChild( "whatShouldTheyContain", sender.whatShouldTheyContain, "" ); + XmlNode & helloWorldNode = bodyNode.addChild( _T("GetArrayOfStrings"), _T(""), _T("") ); + helloWorldNode.addNamespace( XmlNamespace( _T("http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject") ) ); + helloWorldNode.addChild( _T("howMany"), boost::lexical_cast< tstring >( sender.howMany ), _T("") ); + helloWorldNode.addChild( _T("whatShouldTheyContain"), sender.whatShouldTheyContain, _T("") ); return doc.toString(); } @@ -137,7 +137,7 @@ } }; -vector< string > getArrayOfStrings( const string & content, int howMany ) +vector< tstring > getArrayOfStrings( const tstring & content, int howMany ) { GetArrayOfStringsSender sender; sender.howMany = howMany; @@ -149,8 +149,8 @@ // Then we create our SoapRequest SoapRequest< GetArrayOfStringsSerializer, GetArrayOfStringsSender, GetArrayOfStringsReturnValue > soap( "localhost", // Which host is our WebService located at - "/Tester1Endpoint/CustomObjects.asmx", // What is the PATH to our WebService - "SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/GetArrayOfStrings\"", // What is the SOAPAction or basically the NAMESPACE of our WebService + the name of the function we're calling + _T("/Tester1Endpoint/CustomObjects.asmx"), // What is the PATH to our WebService + _T("SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/GetArrayOfStrings\""), // What is the SOAPAction or basically the NAMESPACE of our WebService + the name of the function we're calling 80, // Which TCP/IP port is the WebService listening on serializer, // The serializer/deserializer for our WebService call sender // The object we actually want to send @@ -169,14 +169,14 @@ class TestReturnStuffContents { public: - string stringValue; + tstring stringValue; }; class TestReturnStuff { public: int intValue; - string stringValue; + tstring stringValue; double decimalValue; vector< TestReturnStuffContents > arrayOfContents; }; @@ -184,27 +184,27 @@ class TestGetStuff { public: - string getStuffString; + tstring getStuffString; }; class GetCustomObjectSerializer { public: - string serialize( const TestGetStuff & sender ) + tstring serialize( const TestGetStuff & sender ) { // We're using the SmartXML classes to serialize our request - XmlDocument doc( "Envelope", "", "soap" ); + XmlDocument doc( _T("Envelope"), _T(""), _T("soap") ); XmlNode & rootNode = ( * doc.getDocumentNode() ); - 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" ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema-instance"), _T("xsi") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema"), _T("xsd") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://schemas.xmlsoap.org/soap/envelope/"), _T("soap") ) ); - XmlNode & bodyNode = rootNode.addChild( "Body", "", "soap" ); + XmlNode & bodyNode = rootNode.addChild( _T("Body"), _T(""), _T("soap") ); - XmlNode & helloWorldNode = bodyNode.addChild( "GetCustomObject", "", "" ); - helloWorldNode.addNamespace( XmlNamespace( "http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject" ) ); - XmlNode & getStuffNode = helloWorldNode.addChild( "getStuff", "", "" ); - getStuffNode.addChild( "getStuffString", sender.getStuffString, "" ); + XmlNode & helloWorldNode = bodyNode.addChild( _T("GetCustomObject"), _T(""), _T("") ); + helloWorldNode.addNamespace( XmlNamespace( _T("http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject") ) ); + XmlNode & getStuffNode = helloWorldNode.addChild( _T("getStuff"), _T(""), _T("") ); + getStuffNode.addChild( _T("getStuffString"), sender.getStuffString, _T("") ); return doc.toString(); } @@ -236,8 +236,8 @@ // Then we create our SoapRequest SoapRequest< GetCustomObjectSerializer, TestGetStuff, TestReturnStuff > soap( "localhost", - "/Tester1Endpoint/CustomObjects.asmx", - "SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/GetCustomObject\"", + _T("/Tester1Endpoint/CustomObjects.asmx"), + _T("SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/GetCustomObject\""), 80, serializer, getStuff @@ -268,20 +268,20 @@ class GetDateTimeNowSerializer { public: - string serialize( const GetDateTimeNowRequest & sender ) + tstring serialize( const GetDateTimeNowRequest & sender ) { // We're using the SmartXML classes to serialize our request - XmlDocument doc( "Envelope", "", "soap" ); + XmlDocument doc( _T("Envelope"), _T(""), _T("soap") ); XmlNode & rootNode = * doc.getDocumentNode(); - 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" ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema-instance"), _T("xsi") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://www.w3.org/2001/XMLSchema"), _T("xsd") ) ); + rootNode.addNamespace( XmlNamespace( _T("http://schemas.xmlsoap.org/soap/envelope/"), _T("soap") ) ); - XmlNode & bodyNode = rootNode.addChild( "Body", "", "soap" ); + XmlNode & bodyNode = rootNode.addChild( _T("Body"), _T(""), _T("soap") ); - XmlNode & getDateTimeNow = bodyNode.addChild( "GetDateTimeNow", "", "" ); - getDateTimeNow.addNamespace( XmlNamespace( "http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject" ) ); - getDateTimeNow.addChild( "offset", boost::lexical_cast< string >( sender.offset ), "" ); + XmlNode & getDateTimeNow = bodyNode.addChild( _T("GetDateTimeNow"), _T(""), _T("") ); + getDateTimeNow.addNamespace( XmlNamespace( _T("http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject") ) ); + getDateTimeNow.addChild( _T("offset"), boost::lexical_cast< tstring >( sender.offset ), _T("") ); return doc.toString(); } @@ -290,7 +290,7 @@ GetDateTimeNowResponse retVal; // We're using the SmartXML to deserialize our response - retVal.dateTime = DateTime( ( * document->getDocumentNode() )[0][0][0].getContent(), "yyyy.MM.dd HH:mm:ss" ); + retVal.dateTime = DateTime( ( * document->getDocumentNode() )[0][0][0].getContent(), _T("yyyy.MM.dd HH:mm:ss") ); return retVal; } }; @@ -306,8 +306,8 @@ // Then we create our SoapRequest SoapRequest< GetDateTimeNowSerializer, GetDateTimeNowRequest, GetDateTimeNowResponse > soap( "localhost", - "/Tester1Endpoint/CustomObjects.asmx", - "SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/GetDateTimeNow\"", + _T("/Tester1Endpoint/CustomObjects.asmx"), + _T("SOAPAction:\"http://smartwin.org/SmartSOAP/WebServices/Test/CustomObject/GetDateTimeNow\""), 80, serializer, tmp @@ -327,11 +327,11 @@ { cout << "Calling our WebService with the value of: 2" << endl; cout << "WebService returns: " << endl; - cout << helloWorld( 2 ) << endl << endl; + cout << helloWorld( 2 ).c_str() << endl << endl; cout << "Calling our WebService with the value of: 5" << endl; cout << "WebService returns: " << endl; - cout << helloWorld( 5 ) << endl << endl; + cout << helloWorld( 5 ).c_str() << endl << endl; cout << "Now we're gonna call the WebService with the value 15, this will trigger an Exception which the SmartSOAP will parse for us and 'convert' into an xCeptionSoap..." << endl; try @@ -346,30 +346,30 @@ cout << endl << endl << "Then we're gonna call a bit more 'advanced' WebService function" << endl; cout << "Calling GetArrayOfStrings with 5, 'thomas'" << endl; cout << "Return value was" << endl; - vector< string > strings1 = getArrayOfStrings( "thomas", 5 ); - for ( vector< string >::const_iterator idxIter = strings1.begin(); + vector< tstring > strings1 = getArrayOfStrings( _T("thomas"), 5 ); + for ( vector< tstring >::const_iterator idxIter = strings1.begin(); idxIter != strings1.end(); ++idxIter ) { - cout << "\t\t" << * idxIter << endl; + cout << "\t\t" << (* idxIter).c_str() << endl; } cout << endl << endl << "Then we're call a function taking a custom object returning another custom object" << endl; TestGetStuff getStuff; - getStuff.getStuffString = "Tjobing"; + getStuff.getStuffString = _T("Tjobing"); TestReturnStuff returnStuff = getCustomObject( getStuff ); cout << "Return value was: " << endl; - cout << returnStuff.intValue << endl << returnStuff.stringValue << endl << returnStuff.decimalValue << endl; + cout << returnStuff.intValue << endl << returnStuff.stringValue.c_str() << 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; + cout << "\t\t" << iter->stringValue.c_str() << endl; } - cout << endl << endl << "Then we're call a function returnung a DateTime object" << endl; + cout << endl << endl << "Then we call a function returning a DateTime object" << endl; DateTime date = getDateTimeNowResponse( 1 ); - cout << "Return was: " << date.toDateString( "dd.MM.yyyy" ) << " " << date.toTimeString( "HH:mm:ss" ); + cout << "Return was: " << date.toDateString( _T("dd.MM.yyyy") ).c_str() << " " << date.toTimeString( _T("HH:mm:ss") ).c_str(); string g; cin >> g; |