Calling Web Service

Description

To call Web services, Appeon PowerServer provides a non-autoinstantiated NVO – AppeonWebServiceComponent – as the proxy object to call Web services. The user can either create a local instance of AppeonWebServiceComponent for Web service, or directly use an existing instance of AppeonWebServiceComponent. The user must specify the properties of the instance, such as the proxy type, the Web service location and the class name, to bind the instance with the Web service, or change the instance properties during runtime to dynamically bind with a different Web service.

It provides a universal single interface and a set of parameters which determines which Web service and methods will be called.

Note:

  1. The script to call AppeonWebServiceComponent takes effect on both the Web and the mobile, and has no effect in the PowerBuilder application.

  2. You need to restart the IIS after deploying a Web service with a new method.

appeonwebservicecomponent object

Properties

Properties for appeonwebservicecomponent.

Properties

Type

Description

CallType

String

The proxy type of the Web service to be called.

"1" indicates the proxy type is Dynamic Proxy.

"2" indicates the proxy type is DLL Proxy.

PowerServer for J2EE editions support only CallType="1".

ProxyDllOrUrl

String

If CallType="1", it indicates the URL of the Web service to be called, for example, http://localhost/webservice.asmx (the string "http://" is required);

If CallType="2", it indicates the DLL name of the proxy used by the Web service to be called.

ClassDescript

String

If CallType="1", it can be null;

If CallType="2", it indicates the class name of the nonvisual object deployed as the Web service on the server side.

ReturnValue

Any

Read-only. The return value of functions. The value and value type varies from function to function.

ErrorText

String

Read-only. The error message of functions. The message varies from function to function. Empty string if no error.

Functions
of_callwebservice

Description

Calls the function in the binding Web service.

Syntax

of_callwebservice ( value string methodname {, ref any paralist[]})

Argument

Description

methodname

The name of the Web service method.

paralist[]

Optional. Arrays of Any type. Specifies the parameter arrays for the Web service function.

Passing by reference as well as complexed data types such as array, structure etc. to paralist[] is unsupported.

Return value

Long.

0 – Call succeeded. Gets the value from the ReturnValue property of the proxy object.

-1 – Call failed. Gets the error message from the ErrorText property of the proxy object.

Usage

Before calling this function, use the proxy object properties to bind with the target Web service. If the Web service method contains no parameters, simply specify the method name. If the Web service method contains parameters, define an Any type array before the call, then place the argument to the array, finally pass the array as the second parameter of the function.

Examples

Example 1: the interface contains no parameters.

appeonwebservicecomponent caller
caller= create appeonwebservicecomponent
caller.calltype="1"
caller.proxydllorurl="http://localhost/webservice.asmx"
caller.classdescript=""
integer IRet
IRet=caller.of_callwebservice("GetUserName")

Example 2: the interface contains two parameters, their types are any.

any paralist[]
appeonwebservicecomponent caller
caller=create appeonwebservicecomponent
caller.calltype="1"
caller.proxydllorurl="http://localhost/webservice.asmx"
caller.classdescript=""
paralist[1]="param1"
paralist[2]="param2"
IRet=caller.of_callwebservice("GetUserName",paralist)
Events
Constructor

Description

It will be triggered when you create an instance from a user-defined proxy object inherited from AppeonWebServiceComponent.

Event ID

pbm_constructor

Argument

None

Return values

Long

Usage

Do not write scripts to this event directly, because the scripts will be abandoned when the application is deployed. Instead, define and inherit an object from AppeonWebServiceComponent, and add the scripts to the Constructor event of the new object. The usage is the same as that of the PowerBuilder system object. For example, you can initialize the property value of this event, or define relevant information objects.

Destructor

Description

It will be triggered when you explicitly call Destroy to destroy the instance of a user-defined proxy object inherited from AppeonWebServiceComponent.

Event ID

pbm_destructor

Argument

None

Return value

Long

Usage

Do not write scripts to this event directly, because the scripts will be abandoned when the application is deployed. Instead, define and inherit an object from AppeonWebServiceComponent, and add the scripts to the Destructor event of the new object. The usage is the same as that of the PowerBuilder system object. For example, you can add scripts to release the instances related with the proxy object.

Code Examples

Example 1:

long IRet
int iResult
string strError
appeonwebservicecomponent caller

// create appeonwebservicecomponent instance and set properties

caller=create appeonwebservicecomponent

// if proxy type is DynamicProxy, the value of calltype is 1;
// if proxy type is DllProxy type, the value of calltype is 2.
// PowerServer for J2EE editions support only CallType="1".
// PowerServer for .NET edition supports both.

caller.calltype="1"

// since proxy type is DynamicProxy,the value of proxydllorurl is the address of
// the webservice to be called;or else, the value of proxydllorurl is the name
// of DLL.
caller.proxydllorurl="http://localhost/webservice.asmx"
caller.classdescript=""

// Invoke webservice method

IRet=caller.of_callwebservice("GetUserName")
if IRet=0 then
 iResult=caller.ReturnValue
else
 strError=caller.ErrorText
end if

Example 2:

long IRet
int iResult
string strError
any paralist[]
appeonwebservicecomponent caller

// create appeonwebservice instance and set properties

caller=create appeonwebservicecomponent
caller.calltype="1"
caller.proxydllorurl="http://localhost/webservice.asmx"
caller.classdescript=""
paralist[1]="param1"
paralist[2]="param2"

// invoke webservice method

IRet=caller.of_callwebservice("GetUserName",paralist)

Example 3:

long IRet
int iResult
string strError
appeonwebservicecomponent caller

// create appeonwebservicecomponent instance and set properties

caller=create appeonwebservicecomponent
caller.calltype="2"
caller.proxydllorurl="DotDllForJava"
caller.classdescript="MyJavaWebService"

// invoke webservice method

IRet=caller.of_callwebservice("GetUserName")
if IRet=0 then
 iResult=caller.ReturnValue
else
 strError=caller.ErrorText
end if