Main BLOGGER
Google
WWW THIS BLOG
Friday, June 03, 2005
 
Using gsoap in .NET visual studio

----------------------------------------
From .h file, create server side project
----------------------------------------
(1) Project propery setting
[Menu Project]-->[Property]
<1> Turn off pre-compiled headers
[C/C++]-->[Precomplied Headers]-->
set [Create/Use Precomplied Headers] to "Not Using Precompiled Headers"

<2> Win32 builds need "wsock32.lib"
[Linker]-->[Input]-->
set [additional depedencies] to "wsock32.lib"
--> check the setting by
[Configuration Properties]-->[Linker]-->[commandline] to see if "wsock32.lib" is in the command line

<3> Add gSoap home directory to the include path
[C/C++]-->[General]-->set [Additional Include Directories] to gSoap Home Directory

(2) Specify a custom build step for .h file.
<1> Set gSoap tools path
[Menu Tools]-->[Options]-->[Projects]-->[VC++ Directories]-->
add gSoap Home directory

<2> Create the .h file and Right-click it
[properties]-->[Custom Build Step]-->[Commond Line]-->
Enter 'soapcpp2.exe "$(inputPath)"' --> [output] -->
Enter 'soapStub.h soapH.h soapC.cpp soapClient.cpp soapServer.cpp soapClientLib.cpp soapServerLib.cpp'

(3) Add gSoap files to projects
source files
1. stdsoap2.cpp [gsoap runtime in gsoap home directory]
2. soapServerLib.cpp [server library in project directory]
3. soapC.cpp [serialize/de-serialize library in project directory]
header files
1. soapH.h [project directory]

(4) write implementation functions in a separate CPP file
copy the definition from soapStub.h [Service Operations]
for example


/****************************************************************************** * *
* Service Operations *
* *
\******************************************************************************/


SOAP_FMAC5 int SOAP_FMAC6 mcws__installCode(struct soap*,
struct xsd__base64Binary *code,
struct mcws__retValue &result);

SOAP_FMAC5 int SOAP_FMAC6 mcws__invokeCode(struct soap*,
char *name,
struct mcws__retValue &result);


Then you can create the implementation in the CPP file

#include "soapH.h"

int mcws__installCode(struct soap*,
struct xsd__base64Binary *code,
struct mcws__retValue &result)
{
return SOAP_OK;
}
int mcws__invokeCode(struct soap*,
char *name,
struct mcws__retValue &result)
{
return SOAP_OK;
}


All the data structures are also defined in soapStub.h

(5) add including files in main.cpp
#include "soapH.h"
#include "MySoapService.nsmap"


#include "soapH.h"
#include "Mcws.nsmap"
int main()
{
struct soap soap;
int m, s; // master and slave sockets
soap_init(&soap);
m = soap_bind(&soap, "localhost", 20065, 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) // process RPC request
soap_print_fault(&soap, stderr); // print error
fprintf(stderr, "request served\n");
soap_destroy(&soap); // clean up class instances
soap_end(&soap); // clean up everything and close socket
}
}
soap_done(&soap); // close master socket and detach environment
}



------------------------------------------
From wsdl file, create client side project
------------------------------------------
(1)generate serviceDef.h
1. copy typemap.dat from gsoap home directory
2. copy generated wsdl file from service project directory
3. run "wsdl2h -o serviceDef.h mySoapService.wsdl"

(2) see project settings above

(3) repeat the steps above to generate gsoap files or simply
copy files "soapH.h soapC.cpp soapStub.cpp soapClient.cpp soapClientLib.cpp soapMySoapServiceProxy.h MySoapService.nsmap" to client project directory from service project directory.

(4) add including files
#include "soapMySoapServiceProxy.h"
#include "ns.nsmap"




<< Home

Powered by Blogger

Google
WWW THIS BLOG