Calling .NET Web Services from PB11.5

On the eve of this historic event – the Inauguration of Barack Obama as our 44th President – I thought it only fitting to provide a post that combined PowerBuilder with Politics… The web service in question serves up a random quote from our incomparable, (and soon to be unemployed) 43rd President, George W. Bush.

This entry will show you how easy it is to consume a web service using the .NET web services engine within PB11.5.

Step 1. Get yourself some WSDL
The language of SOAP-based web services is WSDL, or Web Services Descriptor Language. This highly arcane XML syntax contains the entire description of a web service, from the methods it exposes to the datatypes of the parameters it accepts and returns. Most web service engines will serve up the WSDL for their service by simply adding ?WSDL to the end of the URL. For example, we’ll be using the service at http://greg.froh.ca/fun/random_bushism/.
To see the WSDL, use this link: http://greg.froh.ca/fun/random-bushism/soap/?wsdl
(Save that last URL to your clipboard, you’ll need it in step 2 below…)

Step 2. Build a Web Services Proxy
PB11.5 ships with a sample Web Services application. I’ll add the Random Bushisms web service to that application, since it already has most of the app infrastructure in place. That workspace can be found in C:\Documents and Settings\All Users\Documents\Sybase\PowerBuilder 11.5\Code Examples\Web Services.

To create a web services proxy, select File * New. In the Project tab, select Web Service Proxy, as shown in image #1.

File - New dialog

 

The Web Services Proxy project object consists of two tabs – General and Web Service.

Let’s start with the General tab.
Deployment PBL: This is where PB will generate the Proxy class, so you’re selecting a PBL. The best practice (and the standard followed in the example workspace) is to create a PBL specifically for Proxy classes.
Proxy Name Prefix: This allows you to set your naming conventions for the proxy classes and their associated artifacts. I prefer “s” (for service) followed by a sequential number and an underscore. For the Bushism service, I used the prefix s21_

 

Proxy Object Web Services tab

Now on to the Web Service tab (image 2 above).

The top field is the WSDL location, and you have two choices. You can either paste in a URL to web services WSDL somewhere out on the internet, or you can click the button with the elipses to select a file on your local file system that has a .WSDL extension.  In our case, we’re using a public service, so paste in http://greg.froh.ca/fun/random_bushism/soap/?WSDL.  (I told you that you’d need it…)

Note: If this URL is unreachable or returns an error, I’ve included the .WSDL file in the PB115_webservices.zip file, which can be downloaded from http://blogs.sybase.com/phoran/wp-content/uploads/2009/03/pb115_webservices.zip.  PH

The next step is to click the Services… button.  This causes PB to introspect the WSDL file, and bring back this nice graphical treeview dialog containing the methods and structures contained in the WSDL.  Here’s what that dialog looks like:

Web Service structures and methods

Trust me – be thankful for this dialog.  You don’t want to have to read that WSDL syntax yourself…  What you’re doing in this dialog is selecting the service’s methods that you want to expose through the proxy. And, if those services return structures instead of simple datatypes as parameters, you’ll select the corresponding structures as well. This service is fairly simple – there’s one method: RandomBushismService, and one structure: RandomBushism.

Finally, in the WSDL Engine box, select the .NET engine, and provide a name for the .NET assembly DLL that will be generated. Click Save to save the project definition, and click Deploy to create the proxy. You should see two new entries in the Proxies PBL.

s21_randombushismservice:  This is the proxy itself.  You can open it and see the exposed method “getRandomBushism()”.

s21_randombushism:  This is an NVO with two public instance variables – Bushism and Context, which represents the structure returned from the web service call.

Step 3. Create a visual interface to display the results.
In the tabpages.pbl file, the ancestor class uo_ancestor contains all the plumbing to instantiate the service proxy. All you need to do is provide the invocation code, and then process the output. Since the service returns two strings – the quote itself, and the corresponding context in which it was said, I created a simple layout with two statictext controls.

 

Bushisms user object

 

 

In the clicked event of the Invoke button, add the following code:

s21_randombushismservice px_Service
s21_randombushism lstr_bushism

if instantiateService(px_Service, "s21_randombushismservice") then

TRY
   lstr_bushism = px_Service.getRandomBushism( )

   st_bushism.text = lstr_bushism.bushism
   st_context.text = lstr_bushism.context

CATCH (Throwable t)
   MessageBox("Invocation Error", t.GetMessage(), StopSign!)
END TRY

 

 

end if

It couldn’t be simpler. Instantiate the proxy class, invoke the method, use the results…
Save the object into the tabpages.PBL as uo_bushisms. The instantiateService() method is defined in the ancestor class uo_ancestor, so browse that at your discretion.

Step 4. Add the new service definition to the Service treeview.
The final step hooks this all together and allows the application to run with our changes. This isn’t really a requirement to get Web Services working from PB, it’s just to get them callable from this particular application. The main treeview is driven from a datawindow whose resultset is hard-coded into the .data attribute.

In the ws.pbl file, open the datawindow d_svclist.

If the Data pane is not visible, select View * Data, then go to the Data tab.

Insert a new row, and add the following column values (these can be copied and pasted from here):

svctype:     RPC
svcname:   Random Bushism
svcdesc:    Retrieve a random George Bush quotation
svcwsdl:    http://greg.froh.ca/fun/random-bushism/soap/?wsdl
svcsrc:       http://www.xmethods.com/ve2/ViewListing.po?key=uuid:83F65DE6-6676-676A-C8F3-213660CD696E

svcimpl:    Microsoft .NET
svcuo:        uo_bushisms
svcstatus: Y

Save the datawindow, then try running it!

Web Services sample application

I’ve uploaded the workspace with all these revisions intact into the PB115_webservices.zip file.

Enjoy!
-Paul-

Advertisements

About Paul Horan

Software Technology - lots of experience with Sybase and IBM mobility/cloud offerings.
This entry was posted in PowerBuilder, Software and tagged , , , . Bookmark the permalink.

34 Responses to Calling .NET Web Services from PB11.5

  1. Maria Luisa Munizaga says:

    hi i want developed this example but i have error
    i can’t conect to this site when i click on service buttom
    the message error is
    Cannot accesss the WSDL or the WSDL fin is
    invalid.(http://greg.froh.ca/fun/random-bushism/soap/?wsdl)

  2. noazdad says:

    It works fine from this workstation… Could that site be blocked in your browser?

    I’ll add the WSDL as a text file in the download .zip file.
    -Paul-

  3. mmv says:

    Hey, I was trying to use my company developed webservice. I can open/view ?wsdl file in IE. But when i paste url in WSDL location and cliecks on service button, it gives this error.

    Cannot parse the WSDL file.

    Any workaround for this?

    Thanks

  4. noazdad says:

    Are you using the EasySoap engine or the .NET engine?
    What version of PB are you using?

  5. mmv says:

    easySoap. PB 11.5.

    Thanks.

  6. mmv says:

    If you give me your personal email id, i can give you more info on website for webservice. Thanks for helping.

  7. mmv says:

    I made changes in the url and now get this message

    The data type, ‘schema’, is not supported.

  8. Paul Horan says:

    @MMV – don’t use EasySoap. Try the .NET engine.

  9. mmv says:

    get this message on using .net.

    “cannnot access the wsdl or the wsdl file is invalid. (url or wsdl) ”

    Is there any specific path were to put “”assembly name”?

    Thanks

  10. noazdad says:

    Can you e-mail me the WSDL file? Don’t send the one that you see in IE – that has a stylesheet applied that adds the expand/collapse buttons. Instead, do View Source and save that to a .WSDL file. Send to phoran at sybase dot com

    Put the .DLL anywhere you like, but I typically put it in the same folder as the .EXE file for your compiled app.

    -P-

  11. Thomas Stahl says:

    I’m using a WebService „https://www.eanvportal.de/test-ws/BegleitscheinService?wsdl“ (.NET engine). When I deploy the WS, some of the structures are corrupt. For example: the structure nameundadressetyp includes the structures nametype, adressetype and postfachtype. After deploying there is only the structure nametype in nameundadressetyp and a new variable called “item”, datatype “any”. I’m checking the WS in SoapUI, but there is all correct.
    Have you any idea what’s going wrong?
    Thanks for your help.

  12. noazdad says:

    Hmmm… It worked fine for me. What version/build of PB are you using? I’m on 11.5.1.4716. I’ll e-mail you the PBL it generated, with all the structures and the proxy class.
    -P-

  13. Thomas Stahl says:

    Hello Paul. I’m using Build 4675. But now (wheels spinning in my mind for 2 weeks), I’ve found the error, there’s an optional structur in this WebService. Although according to the documentation of the provider the structure is fix. Thanks anyway!

  14. Bernardo says:

    Hi Paul, Im wondering if you could help me with a webservice, when I try to access the wsdl http://www.pmi.com.mx/wsInspectors/ProductsInfoImpl.wsdl it doesnt show me the services of the WS, I really dont know what could be the problem, please I need some help here.

    Thanks

  15. noazdad says:

    Note: my blog has been moved to blogs.sybase.com/phoran.

    What version of PB are you using? That web service requires authentication – do you have a username/password for it?

  16. Bernardo says:

    Thanks for the response Paul, I am using PB 10.5, I do have the user and password, but at the moment PB isn’t asking me for a user or pwd, if you give me a e-mail or something I can send you the screens and the wsdl in a file

  17. noazdad says:

    No problem… I don’t have 10.5 installed any longer, but I can give it a try in 11.5 and 12.0. It’s phoran at sybase dot com.

    Are you using the .NET web services engine, or the EasySoap implementation?

  18. Bernardo says:

    Im using EasySoap, the webservice was created in Java, but I dont think that has something to do with my problem.

  19. wietchie says:

    i have the same problem using PowerBuilder 12 and .Net engine
    “cannnot access the wsdl or the wsdl file is invalid. (url or wsdl)

  20. mike c says:

    I am getting the error message “Cannot access the WSDL or the WSDL file is invalid” when I try to create a .net web services engine in PB 12.1, but don’t have the problem in 12.5. We currently cannot use PB 12.5 with our app, so forced to use 12.1. Do you have any ideas of why we are getting this message on a valid WSDL?

  21. noazdad says:

    Do you have a URL to the WSDL? Is it public?

  22. mike c says:

    Thanks for your response. Yes, the url is https://hie.adph.state.al.us/services/….?wsdl
    The problem that is perplexing is this same url can be cut and pasted into the same web service wizard in version 12.5 and works without a problem. Is there a file that maybe missing in the 12.1 version? We have 3 machines all running the same XP OS. 2 machines cannot run this WSDL in 12.1, but one of them can. The one that can is a newly reformatted machine.

  23. noazdad says:

    Mike,
    That URL is incomplete…

    12.1 works just fine with SOAP-based web services – just make sure you have the .NET SDK (not just the framework) installed.

    BTW – I don’t maintain this blog actively any longer. Please visit blogs.sybase.com/phoran in the future, or drop by the newsgroups at nntp://forums.sybase.com.

    -Paul-

  24. JoseAlegria says:

    hi, everybody

    somebody know send authentication with WS-SECURITY webservice using powerbuilder 11.5 , I’ve tried so many ways, but i can’t do it

    😦

    thanks in advanced

    sorry my english

  25. noazdad says:

    Jose,
    WS-SECURITY is not supported in PB 11.5… You need to use the WCF Client feature of PB12.5 for .NET, so it will require an upgrade.

    -Paul-
    Note: this blog has moved to blogs.sybase.com/phoran

  26. sundar says:

    how to connect pb12.5 to webservice, if you have idea could you please provide the steps

  27. noazdad says:

    You can create either a webservice datawindow (a datawindow object with a SOAP-based web service as the datasource), or you can create a Web Service proxy object.
    Both of these options are fully documented in the 12.5 Help files.

    -Paul-

  28. sundar says:

    is it save PB window and datawindow event code in .cs file, if you save what types of error(issue) will come

  29. Linda D. says:

    Paul, thanks so much for posting this. I’ve made it to the last step, but I am using a different web service from the one in your example. It is not publicly available on xmethods.com. How does one obtain the value for the svcsrv?

  30. noazdad says:

    I’m pretty sure that field is not important. See what happens if you leave it blank.

  31. lindanbc says:

    Hi Paul, right you are. It is just used on the first tab for the WSDL link. Not the problem.

    I think the problem is that the web service, DocuSign, uses HTTPS, whereas the Example library provides only HTTP examples. I’m new at this, and bridging the gap from DocuSign’s descriptions to PowerBuilder is difficult. I followed DocuSign’s steps on:

    https://www.docusign.com/developer-center/quick-start/first-api-call

    I set up a demo account and obtained an “Integrator Key”.

    I created the proxy object per your tutorial. When I run it, I get “User_Authentication_Failed – Missing authentication header”.

    I tried adding a call to setbasicauthentication, but it made no difference. Maybe it’s the wrong thing or maybe I have it formatted incorrectly, or maybe there’s a missing step!

    Here’s an overview:

    (The service I chose to test returns 3 pieces of information, one of which is an array, so I put 2 sle’s and an mle on the uo_docusign.)

    1. In uo_ancestor.Constructor, create a soapconnection object ().
    2. In uo_docusign.Constructor, call setbasicauthentication function, passing 3 args:
    “demo.docusign.net”,
    my [DocuSignIntegrator Key]email address in a string, and
    my DocuSign password.

    This returns success.

    3. In uo_dosusign.cb_invoke.Clicked – here is my script (masked the credentials)
    integer i
    string accountid = “5d8c31ac-***************-0f7c26eabe28” // my demo account

    s20_dsapiservice px_Service
    s20_accountmembershipfeatureslist lstr_dsamfl

    if instantiateService(px_Service, “s20_dsapiservice”) then

    TRY
    lstr_dsamfl = px_Service.getAccountMembershipFeaturesList(accountid)
    st_email.text = lstr_dsamfl.email
    FOR i = 1 to UpperBound (lstr_dsamfl.enabledfeaturesset)
    mle_enabledfeaturesset.text = &
    mle_enabledfeaturesset.text + “;” + lstr_dsamfl.enabledfeaturesset[i]
    NEXT
    st_username.text = lstr_dsamfl.username

    CATCH (Throwable t)
    MessageBox(“Invocation Error”, t.GetMessage(), StopSign!)
    END TRY

    This throws an exception upon the call to getAccountMembershipFeaturesList:
    “User_Authentication_Failed – Missing authentication header”.

    Can you point me in the right direction for resolving this? I’ve been using PB for over 20 years, but am completely new to Web Services. I’m using PB 12.5.2 Classic on Windows 7.

    Thanks much,
    Linda

  32. lindanbc says:

    Hi Paul,
    Problem resolved. I had the wrong URL for SetBasicAuthentication. In resolving that, I discovered that DocuSign has a separate Credential Service that you can instantiate in order to call their Login function, which returns the Base URL that is needed for the SetBasicAuthentication function. Thanks again for your tutorial. It really helped. –Linda

  33. Hi

    I have this Web Service …
    http://www.mtzmarcel.com.mx/test/ws/service.php?wsdl

    When I click on Services botton I can see the services and structures but when I select .NET engine and put on Assembly Name c:/Fut-Soft/prueba.dll I have gotten the error

    Cannot acces the WSDL or the WSDL file is Invalid

    What’s wrong? Could you help me please?

  34. noazdad says:

    Joak,
    PB12.6 Classic (build 4081) consumed that WSDL just fine. I was able to create a WebService proxy project that referenced that WSDL and generated out the appropriate classes.
    What version/build are you using?

    -Paul-

Comments are closed.