首页 > 开发 > 综合 > 正文

EAServer Web Service Using PowerBuilder Component

2024-07-21 02:10:14
字体:
来源:转载
供稿:网友



easerver web service using powerbuilder component and client



this document illustrates how to use a powerbuilder component as a

web service hosted in easerver, and use a powerbuilder client to call

the web service. instructions are provided to:
create and deploy a powerbuilder component expose the pb component as a web service using easerver web services toolkit create a powerbuilder proxy using the wsdl file call the web service from a powerbuilder client
before you begin

·  ensure the easerver server you will be using is up and running

·  define an easerver profile in powerbuilder, and test it to verify the connection is successful.

·  note that these instructions assume host=localhost, and http port=8080. please adjust these values to match your environment.

step a - create and deploy a powerbuilder component

in this section, we will create a simple powerbuilder component and deploy it to easerver. the component will have one method, that receives and retruns a string.
start powerbuilder 9 and create a new workspace create a new target, based on the following information. accept the defaults for all other values.
target type:

easerver component

interface options

new interface

powerbuilder object name:

n_pbhello

easerver component name:

n_pbhello

easerver profile:

as appropriate to connect to your server

package name:

mywebservices
add a function to n_pbhello, based on the following information:
function name:

fhello

return type:

string

argument:

type: string
name: asname

code:

return "hello " +asname + " from pb web service";
deploy the project generate stubs for the component in easerver run jaguar manager and connect to your easerver server expand the mywebservices package. right-click the n_pbhello component and choose generate stubs and skeletons from the popup menu.
choose these options:
-- generate stubs
-- generate java files
-- java code base: the location to your easerver /html/classes directory
-- compile java stubs
click generate, and verify that the last line of the code generation status window shows "code generation completed successfully"
step b - expose the component as a web service using easerver web services toolkit

in this section, we will use the easerver web services toolkit to create the wsdl to expose the component as a web service.
run jaguar manager choose connect | web services toolkit from the tools menu, and specify the login information for your easerver server select the wsdl documents folder and choose new wsdl document from the file menu. specify these values:
definition name:

pbhello

target namespace:

http://localhost:8080/pbhelloimpl
click ok to create the entry select the pbhello entry and choose new web service from the file menu on the new web service window, click browse to display a list of the eligable components.





choose the n_pbhello component under the mywebservices package and click ok.
(tip: restart the easerver server if you do not see the component included in the list.)
verify the selection is filled in as the web service name.



click ok
right-click mywebservices/n_pbwebserviceservice in the details pane click choose porperties from the popup


the web services properties window appears. click add addresses the web service addresses window appears


specify 8080 as the port specify localhost as the host click add so an entry is included in the current addresses list click ok to close the window
11. the address appears in the list.





click select operations...
the methods that are eligible as a web service operation appear.



select fhello and click ok.
the desired address and operation have now been specifed.



click ok to close the window. the wsdl is now complete. easerver created two wsdl files for you: pbhelloimpl.wsdl and pbhello.wsdl, in the %easerver%/webservices/work/wsdl
now just need to put the wsdl files into an appropriate directory so they can be access via an http url.
copy pbhelloimpl.wsdl and pbhello.wsdl from your %easerver%/webservices/work/wsdl directory into the %easerver%/html directory.
step c - create a powerbuilder proxy using the wsdl file

in this section, we will create a proxy object in powerbuilder, to allow us to invoke the web service from a powerbuilder client.
start powerbuilder 9 and create a new workspace. create an application object, add add the following to the library list: pbsoapclient90.pbd
the soapconnection and soapexception objects will now be included in the tree





create a new project, of type web service proxy wizard.
specify the wsdl file as follows, to be served up from the easerver http listener:




select the service found in the wsdl fle:




select the port for the service:




step through the rest of the wizard to create the project. select the project and deploy it.
 



create a new window with a button, and add this code the button clicked event:
5.             

6.            soapconnection lsc_soapconn

7.           string ls_soapresponse

8.           long   ll_result

9.           mywebservices_n_pbhelloserviceport proxy_obj

10.       

11.      // initialize

12.      lsc_soapconn = create soapconnection

13.       

14.      // create proxy object

15.      ll_result = lsc_soapconn.createinstance(proxy_obj, &

16.         "mywebservices_n_pbhelloserviceport")

17.       

18.      if ll_result = 0 then

19.                try

20.                          // invoke service and display result

21.                          ls_soapresponse = proxy_obj.fhello("jackie")

22.                          messagebox("soap response", ls_soapresponse)  

23.                catch ( soapexception e )

24.                          // error handling

25.                          messagebox ("error", "cannot invoke web service." &

26.                            + " exception info: " + e.text)

27.                end try

28.      else

29.                messagebox ("error: " + string(ll_result), &

30.                          "unable to create proxy")

31.      end if

32.       

33.      // clean up

34.       destroy lsc_soapconn

 
run the window and click the button to invoke the web service and display the result:



for more information

see the easerver web services toolkit user's guide, and the developing web applications section of powerbuilder application techniques.
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表