Using gsoap for web services in symbian

 

Using gsoap for web services

From Forum Nokia Wiki

With the time-to-market being so critical for mobile applications, One would certainly like to have as much reusable components as possible. This is where generic components come into picture.

Contents

[hide]

*               1 Problem statement

*               2 What is gSOAP

*               3 Why gSOAP

*               4 How to use gSOAP

*                       4.1 Step1: Generating the header file

*                       4.2 Step2: Generating C++ code

*                       4.3 Step3: Include generated file to your project directory

*               5 Multithreading for non-blocking calls

Problem statement

Let us say you want to design a S60 application with SOAP/XML web services communication. Nokia provides a WSDL-to-C++ tool to generate stubs from wsdl file and Xmldatabinding libraryto run this code. However, later if you decide to port this application to UIQ( or even Samsung S60 devices), you need to re-design your application as this library is provided by Nokia and doesn't work on other platforms or even S60 devices from other manufacturers. How to avoid this problem by making the SOAP communication generic for all platforms. The answer is gsoap.

What is gSOAP

A cross-platform open source C and C++ software development toolkit. Generates C/C++ RPC code, XML data bindings, and efficient schema-specific parsers for SOAP Web services.

Why gSOAP

The primary reason to go for gSOAPis portability.gSOAP supports most platforms, including embedded systems and small OS (for example WinCE, Symbian, and PalmOS).

How to use gSOAP

Download the latest gSOAP package from the SourceForge gSOAP project site. The gSOAP distribution package includes two compiler tools to develop your applications:

'wsdl2h' WSDL parser: This tool converts WSDLs and XSD files into annotated C/C++ definitions.

'soapcpp2' stub and skeleton compiler :This tool generates RPC code and XML serializers from the annotated C/C++ definitions.

The 'wsdl2h' parser converts WSDL into gSOAP header file specifications of Web services. This specification gives a C/C++ transparent view of the server's functionality. The header file is processed by 'soapcpp2' to generate the source code stubs and skeletons to invoke the service or build a new service based on the WSDL.

Step1: Generating the header file

The first step is to generate the header file from your wsdl file using the wsdl2h tool. We may need to modify the typemap.dat file to include the namespaces corresponding to our wsdl. If the namespace is unspecified, the wsd2l tool will use the default ns1...ns2 values. In essence a namespace aims to provide unique means to identify a type.

wsdl2h -s -t typemap.dat -o soapProxy.h mywebservice.wsdl
 
-s indicates that code that relies on STL should not be generated since the STL is not available for Symbian.
 
-o specifies the output name of the file;
 
-t specifies the Specific typemap.dat to be used.
 
for more options, use wsdl2h -help

Step2: Generating C++ code

We need to run the soapProxy.h through the gSOAP compiler in order to create the proxy, serializers and namespace mapping file.

The soapcpp2.exe is used with the following parameters:

soapcpp2 -t -C -L soapProxy.h
 
-t indicates that code is to generate typed messages (with the xsi:type attribute).This helps ensure interoperability and compatibility when using RPC-encoded style.
 
-C indicates that only client side code should be generated.
 
-L By default the compiler will attempt to create a soapClientLib.cpp which is relevant for building static or dynamic libraries. This is not relevant to us and is therefore disabled with the -L flag.

Step3: Include generated file to your project directory

Files

FileName

Description

inc

src

soapProxy.h

Defines schema types, services & bindings

X

 

soapStub.h

Amended schema types, services & binding definitions

X

 

soapH.h

XML (de)serializers for data types

X

 

stdsoap2.h

The gSOAP runtime

X

 

myWebServiceSOAP11BindingProxy.h

Proxy to invoke the services

X

 

myWebServiceSOAP12BindingProxy.h

Proxy to invoke the services

X

 

soapC.cpp

 

 

X

soapClient.cpp

 

 

X

stdsoap2.cpp

 

 

X

 

Multithreading for non-blocking calls

To keep the application UI responsive, We can issue the gsoap call in a seperate thread.

void CMyUpdater::StartL()
{
  TInt id
= iThread2.Handle ();
 
if ( (id==KCurrentThreadHandle)||(id==0))
 
{
 
                   
//Thread uses shared heap created within main thread
                    TInt err
= iThread2.Create (_L("myupdater"),ThreadFunction,KDefaultStackSize,NULL,(TAny *)this);
                   
if ( err==KErrNone)
                   
{
                    iStatus
=KRequestPending;
                    SetActive
();
                    iThread2.
Resume ();
                   
}
         
}
}
 
// protected from CActive
void CMyUpdater::DoCancel()
         
{
          TInt id
= iThread2.Handle ();
         
if ( (id!=KCurrentThreadHandle)&&(id!=0))
                   
{
                     User
::After (1000000);
                   
/*Thread request must be indicated as completed
                     * when canceling the thread else the thread is blocked
                     * due to 'User::WaitForRequest()' in 'cancel()'
                     *
                     */

                    TRequestStatus
* status = &iStatus;
                    iThread2.
RequestComplete(status, KErrCancel);

                    iThread2.
Kill (KErrCancel);
                    iThread2.
Close ();
 
                   
}
         
}
 
void CMyUpdater::RunL()
{
         
if ( iStatus==KErrDied || KErrCancel)
         
{
         
//indicate the webservice response is processed - Ani
          iThread2.
Close ();
         
}
         
else
         
{
          SetActive
();
         
}
 
}
 
 
// private new methods
TInt CMyUpdater
::ThreadFunction(TAny *aPtr)
         
{
          CMyUpdater
* ptr = (CMyUpdater*)aPtr;
 
         
// open main thread
          RThread thread
;
          thread.
Open (ptr->iId, EOwnerProcess);
 
         
//Create a cleanup stack
          CTrapCleanup
* cleanup = CTrapCleanup::New ();
         
//Create and install a active scheduler
          CActiveScheduler
* sched(NULL);
          sched
=new CActiveScheduler;
         
if ( !sched)
                   
{
                   
delete cleanup;
                   
return KErrNoMemory;
                   
}
 
          CActiveScheduler
::Install (sched);
 
       TRAPD
(err,ptr->IssueRequestL());
 
          CloseSTDLIB
();
 
          TRequestStatus
* status = &(ptr->iStatus);
          thread.
RequestComplete (status, KErrDied);
 
         
//Delete the heap allocated stuff
         
delete sched;
         
delete cleanup;
         
return KErrNone;
 
         
}
 
 
void CMyUpdater::IssueRequestL()
{
         
//Issue web service request here and check for response
}

Retrieved from "http://wiki.forum.nokia.com/index.php/Using_gsoap_for_web_services"

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值