Page 1 of 1

New Feature: Barebone SOAP Functionality

Posted: Wed Jan 30, 2008 12:22 am
by dlangdev
Hi all,

I'm releasing the code that will provide barebone Win32 SOAP functionality to your irrlicht application.

This will apply only to those projects who like to leverage their SOAP services onto their Irrlict games. Grab a copy and test it in your environment.

Step #1: Copy the code below and paste it in ISoap.h

Code: Select all

// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#ifndef __IRR_SOAP_H_INCLUDED__
#define __IRR_SOAP_H_INCLUDED__

// ISoap.h

#include <stdio.h>

#import "msxml3.dll" 
using namespace MSXML2;

#import "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP1.dll" \
         exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", \
               "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib;

#pragma message("ISoap is included")

namespace irr
{
namespace core
{

class ISoap
{
	public:

		virtual void set_wsdl( const wchar_t* url) {
			wsdlUrl = url;
		}

		virtual void set_soapActionUrl( const wchar_t* actionUrl) {
			soapActionUrl = actionUrl;
		}

		virtual void set_body( const wchar_t* xmlBody) {
			soapXmlBody = xmlBody;
		}

		virtual void send() {
		   // Connect to the service
		   Connector.CreateInstance(__uuidof(HttpConnector));
		   Connector->Property["EndPointURL"] = wsdlUrl;
		   Connector->Connect();

		   // Begin message
		   Connector->Property["SoapAction"] = soapActionUrl;
		   Connector->BeginMessage();

		   // Create the SoapSerializer
		   Serializer.CreateInstance(__uuidof(SoapSerializer));

		   // Connect the serializer to the input stream of the connector
		   Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

		   // Build the SOAP Message
		   Serializer->startEnvelope("","","");
		   Serializer->startBody("");
		   Serializer->writeXML( soapXmlBody );

		   Serializer->endBody();
		   Serializer->endEnvelope();
		   
		   // Send the message to the web service
		   Connector->EndMessage();      

		   // Let us read the response
		   Reader.CreateInstance(__uuidof(SoapReader));

		   // Connect the reader to the output stream of the connector
		   Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");

		   //printf("Webservice Reply ==>  %s\n", (const char *)Reader->RPCResult->xml);

		   xmlResult = strdup( ( const char* )Reader->RPCResult->xml );

		   //printf("output %s\n\n", xmlResult);

		}

		virtual const char* result() {
			return ( xmlResult ) ;
		}
	private:

		const wchar_t* wsdlUrl;
		const wchar_t* soapActionUrl;
		const wchar_t* soapXmlBody;
		const char* xmlResult;

		ISoapSerializerPtr Serializer;
		ISoapReaderPtr Reader;
		ISoapConnectorPtr Connector;


};


} // end namespace core
} // end namespace irr

#endif
Step #2: Test it using this code fragment shown below...

Code: Select all


... more code here ...

#include <ISoap.h>


... more code here ...

    CoInitialize(NULL);

	core::ISoap ws1;

	core::stringw wsdl(L"http://www.mydomain.com/soap/admin.asmx?wsdl");
	core::stringw actionUrl(L"http://www.mydomain.com/soap/getStudentInfo");
	core::stringw soapBody(L"<getUserInfo xmlns='http://www.mydomain.com/soap/ws'><userID>1595526</userID></getUserInfo>");

	ws1.set_wsdl( wsdl.c_str() );
	ws1.set_soapActionUrl( actionUrl.c_str() );
	ws1.set_body( soapBody.c_str() );
	ws1.send();
	const char *ret1 = ws1.result();
                core::stringw s1( ws1.result() );

	if ( strlen(ret1) == 0 ) {
		printf("No return value");
	}

    CoUninitialize();


... more code here ...

By the way, this is not production ready code. You'd be a fool to think it is prod quality.

You will need to study the code and adjust it according to your environment, only then you can apply it to your prod.

Posted: Wed Jan 30, 2008 7:50 pm
by Vsk
what is soap :roll: (you missed that one on the poll:P).

Posted: Wed Feb 06, 2008 8:47 am
by ecsos
this is actually pretty cool.
you could could do a lot of theoretically cool stuff with this

Posted: Wed Feb 06, 2008 9:42 am
by dlangdev
it's not complete, though. it needs to be connected to an xml/xlt library in order for the elements to be extracted.

with that code alone, a lot of interesting things can be made with it. i guess you already seen the beauty and power of its potential.

Posted: Wed Feb 06, 2008 10:58 am
by jingquan
Vsk wrote:what is soap :roll: (you missed that one on the poll:P).
I'll like to know too.

Posted: Wed Feb 06, 2008 11:18 am
by Anteater

Posted: Thu Feb 07, 2008 3:20 pm
by Vsk
Anteater wrote:Wikipedia is your friend. :D
No is not! :P. We are fight for so long. :).

Posted: Thu Feb 07, 2008 9:08 pm
by saigumi
Yeah... I can see some uses for it. The main strength being to get around firewalls (as it acts through the HTTP transport) and have a sort of structure to your messages (XML).

For highspeed twitch games, it is impractical for wasting way too much bandwidth on the XML overhead and extra work to reconstruct the data/break down the XML.

However, if you have something with less messages, less often and easier to understand, that is where SOAP starts usefulness. The other perk is that you can set your WSDL to return formatting info and with that, other apps can then easilly interface with your server. Since SOAP is also cross-platform with lots of implementations, your "Server" could be Apache-PHP, Rails, Grails, etc.

Posted: Sat Feb 09, 2008 1:56 pm
by plotti
SOAP is a nice idea.

Although I think that SIP is much more promising and better suited for this aspect, actually right now i am experimenting with the SIP protocoll and missusing a SIP Voip Stack to provide a network layer for Irrlicht.

Main benefits are:
Simplicity
P2P functionlity
NAT traversal
RTP for time critic apps
and REGISTRAR and PROXY functionalities for easy setup and location.

--> from my point of view this will be the the protocoll to use in the future online gaming.

+ of course if you use SIP , voip comes for free, just like that.
________
MEXICO CITY HOTEL

Posted: Tue Feb 12, 2008 7:43 am
by dlangdev
Why would I want to use SIP instead of SOAP?

<Scratches Head>

Just because SIP can stream sound does not mean it can handle SOAP.

<Scratches Head Again>

<Looks up to the big blue sky>

Posted: Tue Feb 12, 2008 12:58 pm
by plotti
well true comparing soap with sip is like apples and bananas.

is there any application scenario soap could be used in though?

Displaying weather information in the game??
________
CL360

Posted: Tue Feb 19, 2008 9:52 pm
by saigumi
Actual, my team is now using this SOAP implementation as a starter framework for our game, which is a boardgame. Basically, using the SOAP interface seemed fine as we aren't concerned with bandwidth or twitchyness or the need for clients to poll.

Being able to send a SOAP pattern out with a bundle of commands made sense. Yeah, we could streamline it and generate our own packet formats for pure speed, but meh... XML just works for this.

I've actually started coding the server in Rails. This is going to be an interesting project.

Posted: Tue Feb 19, 2008 10:58 pm
by dlangdev
Double post.

Posted: Tue Feb 19, 2008 10:58 pm
by dlangdev
Dear Saigumi:

This is very interesting, I'd like to work with you sometime in the future when you have implemented a working SOAP demo. I have already a sample implementation working, though I can't release it due to personal reasons.

It would be nice to setup a collaborative effort in setting-up a common architecture for SOAP-based applications running on 3D engines like Irrlicht.

If you're interested in writing up a standard for servers and clients running on SOAP, please let me know. We'll put it up on a domain and market it for public and corporate adoption.

I've implemented my sample SOAP demo using MS DotNet, SQL Server, Webservices. And they work pretty well with a remote Irrlicht client. These set of tools could become a standard if we write them up, though. Then market it later.