Switch to standard view 
  Sybase logo
 
 
 



How to use .Net Webservice with PocketBuilder and PocketSoap

Overview

This document explains how to call a .Net Webservice from PocketBuilder using the PocketSoap interface DLL that is available on codeXchange.

It shows the development of a simple .Net webservice using .Net Studio, the development of the PocketBuilder client, and also how PocketBuilder can be used to access
other external Webservices  .

This document assumes that the user has version PocketBuilder 2.0.2 or higher.


ASP.NET WebService
 

We start a new Project in VisualStudio.NET and select a new ASP.NET WebService

The Wizard will create a default WebService function template for Service1 which we can modify, by using the following function signature.

We can now build the WebService1 project and from now on we can access the WebService on the following location:
 
http://localhost/WebService1/Service1.asmx

The Service description available at http://localhost/WebService1/Service1.asmx?WSDL.

For testing the WebService we can use the generated http://localhost/WebService1/Service1.asmx?op=HelloWorld form to see if the function executes
correctly.


 

PocketBuilder and PocketSoap
Pocket PowerBuilder and PocketSOAP interact through an interface/external DLL wrapper, which provides simple access to the PocketSOAP package via its COM interface.
To run with PocketSOAP, retrieve the installs from www.pocketsoap.com and install them on both the desktop and Pocket PC devices. These installs contain the API documentation, which will be useful in the future when we'll code directly to the PocketSOAP COM object via the OleObject. The PocketSOAP wrapper can be found on the CodeXchange Web site, http://pocketpb.codexchange.sybase.com, with other examples.

For more information about WebService technology, accessing WebServices that use RPC binding style with PocketBuilder and PocketSoap follow the document Pocket PowerBuilder, SOAP, and PocketSOAP, available on sys-con.com in the section of the pbdj.

By default, ASP.NET WebMethods are described using document-literal bindings in WSDL. This means that literal XML Schema definitions describe the SOAP Body payload for both the request and response messages.

 
PocketBuilder code
 
After the declaration of the interface functions as global external functions (see readme of the pocketsoap interface), the previously created WebService1
can be accessed by the following code eg. in a commandbutton
string sMethod = "HelloWorld"
string sEndPoint  = "http://localhost/WebService1/Service1.asmx"  //give it the servername of your host machine, where the WebService is deployed to
string sNameSpace = "http://tempuri.org/"
string sEncodingStyle = "" //   this means set to document/literal -  RPC is Default

int    cRetBufLen = 128
string sArgs
string sResult
long   lHandle
int    iRet

TRY
 

 iRet = PocketSoap_Create( true, REF lHandle )
 
 IF iRet < 0 THEN
  MessageBox ("Create Failed", iRet)
 END IF
 
 iRet = PocketSoap_SetEndPoint( lHandle, sEndPoint )
 
 IF iRet < 0 THEN
  MessageBox ("SetEndPoint Failed", iRet)
 END IF
 
 
 //Set encoding style!!!
 //http://www.pocketsoap.com/faq/
 iRet = PocketSoap_SetEncodingStyle( lHandle, sEncodingStyle )
 
 IF iRet < 0 THEN
  MessageBox ("SetEndCodingStyle Failed", iRet)
 END IF
 
 iRet = PocketSoap_SetParameterNameSpace( lHandle, sNameSpace )
 
 IF iRet < 0 THEN
  MessageBox ("SetParameterNameSpace Failed", iRet)
 END IF
 
 
 iRet = PocketSoap_SetSoapAction( lHandle, "http://tempuri.org/HelloWorld" )
 
 IF iRet < 0 THEN
  MessageBox ("SetSoapAction Failed", iRet)
 END IF
 
  // preallocate the result string
 sResult = Space( cRetBufLen )
 
 // make a "simple call"
 iRet =  PocketSoap_SimpleCall( lHandle, sNameSpace, sMethod, "a:name", "Testargument" )
 
 IF iRet < 0 THEN
  MessageBox ("SimpleCall Failed", iRet)
 END IF
 
 iRet =  PocketSoap_GetResult( lHandle, cRetBufLen, REF sResult )
 IF iRet < 0 THEN
  MessageBox ("GetResult Failed", iRet)
 END IF
 

 MessageBox ("Value: ", sResult)
 
 iRet =  PocketSoap_Destroy( lHandle )
 
 IF iRet < 0 THEN
  MessageBox ("Destroy Failed", iRet)
 END IF

 
CATCH (throwable t)
 MessageBox ("Caught throwable", t.GetMessage())
END TRY
 
Note: Normally (ie. when using RPC binding style) the argument name that is being passed to the function  PocketSoap_SimpleCall() is just the argument name
but here the "a:" in front of the argument name needs to be added as a workaround. This might get resolved in a later version.

Accessing a public external WebService at http://www.webservicex.com (can be found via http://www.xmethods.net/)
 

string sMethod = "GetQuote"
string sEndPoint  =  "http://www.webservicex.com/stockquote.asmx"
string sNameSpace = "http://www.webserviceX.NET/"
string sEncodingStyle = "" //   this means set to document/literal -  RPC is Default
int    cRetBufLen = 512 //make it big enough, cos the returned string can be long,
string sArgs
string sResult
long   lHandle
int    iRet

TRY
 

 iRet = PocketSoap_Create( true, REF lHandle )
 
 IF iRet < 0 THEN
  MessageBox ("Create Failed", iRet)
 END IF
 
 iRet = PocketSoap_SetEndPoint( lHandle, sEndPoint )
 
 IF iRet < 0 THEN
  MessageBox ("SetEndPoint Failed", iRet)
 END IF
 
 
 //Set encoding style!!!
 //http://www.pocketsoap.com/faq/
 iRet = PocketSoap_SetEncodingStyle( lHandle, sEncodingStyle )
 
 IF iRet < 0 THEN
  MessageBox ("SetEndCodingStyle Failed", iRet)
 END IF
 
 
 iRet = PocketSoap_SetSoapAction( lHandle, "http://www.webserviceX.NET/GetQuote" )
 
 IF iRet < 0 THEN
  MessageBox ("SetSoapAction Failed", iRet)
 END IF
 
 iRet = PocketSoap_SetParameterNameSpace( lHandle, sNameSpace )
 
 IF iRet < 0 THEN
  MessageBox ("SetParameterNameSpace Failed", iRet)
 END IF
 
  // preallocate the result string
 sResult = Space( cRetBufLen )
 
 // make a "simple call"
 iRet =  PocketSoap_SimpleCall( lHandle, sNameSpace, sMethod, "a:symbol", "SY" )
 
 IF iRet < 0 THEN
  MessageBox ("SimpleCall Failed", iRet)
 END IF
 
 iRet =  PocketSoap_GetResult( lHandle, cRetBufLen, REF sResult )
 IF iRet < 0 THEN
  MessageBox ("GetResult Failed", iRet)
 END IF
 

 MessageBox ("Value: ", sResult)
 
 iRet =  PocketSoap_Destroy( lHandle )
 
 IF iRet < 0 THEN
  MessageBox ("Destroy Failed", iRet)
 END IF

 
CATCH (throwable t)
 MessageBox ("Caught throwable", t.GetMessage())
END TRY


Back to Top
© Copyright 2010, Sybase Inc.