Wednesday, September 5, 2012

Calling Web Service from Powerbuilder

On the last post, I explained how to make web service with Powerbuilder. This time I will explain how to access the web service via PowerBuilder. I am using the Classic version of PowerBuilder 12.5.

The scenario is you have a windows application created with PowerBuilder and you want to access a web service over the internet within the Powerbuilder application.

All you need is certainly a web service that is ready to use. You can get it for free on the internet, or create your own web service. In this example I will create a self service web applications using Visual Studio 2008 and run. NET framework 3.5. In the web service, there is a function that we named of_add2value which serves to add 2 numbers through which we put on the parameters of these functions.

Script functions as below

1:  Public Function of_add2value (ByRef value1 As Decimal, ByRef Value2 As Decimal) As Decimal  
2:       Return value1 + Value2  
3:  end Function  

How to create a web service with Visual Studio 2008, you can look at the Microsoft website.

Once a web service is successfully created, you have to upload it to the internet that is running Microsoft IIS with. NET framework 3.5 as its web server.

Example you uploading to

The next step is that you create a project in PowerBuilder. To be able to access the web service, you have to import the first PB extention named pbwsclient125.pbx that normally exist in the directory c:\program files\sybase\shared\PowerBuilder

Once you have finished importing the PB extension, 3 user objects will appear as shown below (figure 1).

figure 1

Next, you must create a Web Service Proxy Project. To do this, click the File menu, New, select Project, and then select Web Service Project. (see figure 2)
figure 2

On the General tab, enter the information as shown below (figure 3).
figure 3

For Web Service tab, enter the information as shown below (figure 4).

Save the project and give it a name eg: p_misws_wsproxy

You are required to close all window objects that are still open.

In the system tree window, right-click the object p_misws_wsproxy project, and select Deploy. If successful, it will be automatically made ​​a proxy object that has the name ws_service1. Please note the name is based on the data we input during the creation of the Web Service Proxy Object, above. Prefix WS_ is in accordance with the Prefix field, and is in accordance with the Service1 class name in the web service that we created in Visual Studio (figure 5 and 6).
figure 5

figure 6

The final step is to create a window object that will be filled by the script to call the web service. In that window, create a static text object and name st_result, 2 editmask object and name em_1 and em_2, and a button. Save and name it w_helloworld. For more details see the image below

In the button clicked event, type the following script:

1:  SoapConnection conn // Define SoapConnection  
2:  ws_service1 proxy_obj // Declare proxy  
4:  long rVal  
5:  decimal dResult, dValue1, dValue2  
7:  conn = create SoapConnection //Instantiated connection  
9:  rVal = Conn.CreateInstance(proxy_obj, "ws_service1")  
10:  Conn.setbasicauthentication( <yourdomain>, <yourusername>, <yourpassword>)  
12:  // Create proxy object  
13:  try  
14:       dValue1= Dec(em_1.text)  
15:       dValue2= Dec(em_2.text)  
16:       dResult = proxy_obj.of_add2value(dValue1, dValue2)  
17:       st_result.text = String(dResult)  
19:       // Invoke service  
20:  catch ( SoapException e )  
21:       messagebox ("Error "+string(rVal), "Cannot invoke Web service "+e.Text)  
22:       // error handling  
23:  end try  
25:  destroy conn  

Run the application.
figure 7

Please take a note:

  • You must have an internet connection. The speed for connecting, accessing and getting the result  of web service is depending on your bandwidth connection.
  • Powerbuilder provides the connection behind the firewall, by typing the information of proxy server, port number, user account and password. The option located at menu Tools, System Option and Click the Firewall Setting tab (figure 8). But I always failed to use the connection behind the firewall. So, I suggest you to use direct internet connection (without firewall)
figure 8

1 comment :

  1. For more information on Web Development company, check out the info available online; these will help you learn to find the Website Design company.