1. Moshe Tangi
  2. PowerBuilder
  3. Thursday, 20 February 2020 11:33 AM UTC

Hello ,

 

Is it possible to consume wcf web service with powertbuiler 2017 r3 ?

 

if any one have code sample it can be most hekpfull

 

Thanks

David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Friday, 21 February 2020 10:03 AM UTC
  2. PowerBuilder
  3. # 1

Hi Moshe

Here is some test code I used to connect to a "Real World" service:

n_httpclient l_http
string ls_test, ls_response
ulong lul_length
blob lblob_data, lblob_response
integer li_rc


ls_test = '<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header>' + &
'<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">' + &
' <wsse:UsernameToken>' + &
' <wsse:Username>MainstayTest</wsse:Username>' + &
' <wsse:Password>xxxxxxxxxxx</wsse:Password>' + &
' </wsse:UsernameToken>' + &
'</wsse:Security>' + &
'</SOAP-ENV:Header>' + &
'<SOAP-ENV:Body>' + &
' <OTA_PingRQ xmlns="http://www.opentravel.org/OTA/2003/05" EchoToken="123456789" TimeStamp="2019-10-16T17:32:20+01:00" Version="1">' + &
' <EchoData> Hello World </EchoData>' + &
' </OTA_PingRQ>' + &
'</SOAP-ENV:Body>' + &
'</SOAP-ENV:Envelope>'
lblob_data = blob(ls_test, EncodingUTF8!)

l_http = Create n_httpclient
l_http.autoreaddata = true
l_http.secureprotocol = 5 // TLS 1.2
l_http.timeout = 60

lul_length = Len(lblob_data)
li_rc = l_http.clearrequestheaders( )
li_rc = l_http.SetRequestHeader("Content-Length", String(lul_length))
//SetRequestHeader("Content-Type", 'application/soap+xml; charset=utf-8')
li_rc = l_http.SetRequestHeader("Content-Type", 'text/xml;charset=UTF-8')
li_rc = l_http.SetRequestheader( 'Accept-Encoding', 'text/xml;charset=UTF-8')
li_rc = l_http.SetRequestheader( 'Host', 'cmtpi.siteminder.com')
li_rc = l_http.SetRequestheader( 'Connection', 'Keep-Alive')
li_rc = l_http.SetRequestheader( 'User-Agent', 'Apache-HttpClient/4.1.1 (java 1.5)')
li_rc = l_http.SetRequestheader( 'Accept', 'text/xml')
li_rc = l_http.SetRequestHeader("SOAPAction", '"http://www.siteminder.com.au/pmsxchange/PingRQ"')

//messagebox('Headers', l_http.getrequestheaders( ))

li_rc = l_http.sendrequest( 'POST', 'https://cmtpi.siteminder.com/pmsxchangev2/services/MAINSTAY', ls_test)

//https://cmtpi.siteminder.com/pmsxchangev2/services/MAINSTAY
//li_rc = l_http.postdatastart( 'https://cmtpi.siteminder.com/pmsxchangev2/services/MAINSTAY')
//li_rc = l_http.postdata(lblob_data,lul_length)
//li_rc = l_http.postdata( ls_test, len(ls_test))
//li_rc = l_http.postdataend( )

//li_rc = l_http.getresponsebody( ls_response)

li_rc = l_http.getresponsestatuscode( )
li_rc = l_http.getresponsebody( ls_response)

li_rc = len(ls_response)
long ll_file
ll_file = fileopen("c:\temp\response.txt", streammode!,write!,shared!,replace!)
filewrite(ll_file, ls_response)
fileclose(ll_file)
Messagebox('Response',ls_response)

ls_response = l_http.getresponseheaders( )

messagebox('Response Head', ls_response)

//li_rc = l_http.getresponsestatuscode( )
//li_rc = l_http.readdata( lblob_response , 1024*16)
//ls_response = string(lblob_response, EncodingUTF8!)

=====================================================================

The commented out code was used to understand the postdata and readdata functions. I then used sendrequest becuase it is much easier.

The key parts are setting the Header attributes to match the call you are making. Then structure the XML body to match the message structure. Get everything right and it just works :)

 

Comment
There are no comments made yet.
Moshe Tangi Accepted Answer Pending Moderation
  1. Friday, 21 February 2020 08:11 AM UTC
  2. PowerBuilder
  3. # 2

Hi ,

 

Plz see the attached pic below ,

What do I do from here ?

I can see the WSDL file , but I want to consume it with httpclient object and not with soap object

How do I build all the parameters ? the ws  function gets and object array .. How do I apply it with the httpclient object ?

 

Thanks

Attachments (1)
Comment
  1. Mark Lee @Appeon
  2. Friday, 21 February 2020 09:07 AM UTC
Hi Moshe,



1. As we said before in the article, "If you don’t see this XML content, please contact your service provider to get such a sample request."

2. Use a third party tool like Postman to verify what protocol and arguments you need to use to successfully call the Web service API. Regrading how to use Postman, we suggest that you do a Google search or refer to the tutorial on Postman’s official site.

Regards,
  1. Helpful
There are no comments made yet.
Mark Lee @Appeon Accepted Answer Pending Moderation
  1. Friday, 21 February 2020 07:27 AM UTC
  2. PowerBuilder
  3. # 3

Hi Moshe,

Please refer to the bellow article "Call SOAP Web Services Using HTTPClient Object" to rewrite your code to call WCF web service.

https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/236-call-soap-web-services-using-httpclient-object#comment-226,0

You will find that it is using the same code except for the XML Serializer format parameter. However, if you use the string variable to set the value, then there will be no different.

You may utilize the below two objects added in PB 2017 R3 for receiving web service APIs.

HTTPClient https://www.appeon.com/support/documents/appeon_online_help/pb2017r3/objects_and_controls/ch02s37.html

RESTClient

https://www.appeon.com/support/documents/appeon_online_help/pb2017r3/objects_and_controls/ch02s83.html

BTW, if the "Call SOAP Web Services Using HTTPClient Object" article can’t help you, please also let us know. 

You can report it to our support ticketing system (https://www.appeon.com/standardsupport/newbug) with a sample reproducible test case to us for study.

Regards,

Comment
  1. Moshe Tangi
  2. Friday, 21 February 2020 08:52 AM UTC
Hi Mark

Thanks for your response

I comment with a pic below , plz refer to it .

The WS functions gets array of objects and return an object.

I don't know how do I fill the array of objects to the ws function with httpclient ..the actual way ..

Thanks
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 20 February 2020 18:47 PM UTC
  2. PowerBuilder
  3. # 4

Hi Moshe;

   FWIW:  I have not tried interacting with WCF specifically, but I am guessing that the new HTTPClient will be able to interact with a WCF Web Service. One of the main challenges though is when the WCF WS responds. It will probably use an XML format. For parsing that XML data stream, you will have to use the PBDOM feature of PB.

Regards ... Chris

Comment
  1. David Peace (Powersoft)
  2. Friday, 21 February 2020 09:51 AM UTC
I have used both SoapClient and HttpClient to connect to WCF web services. Moshe is specifically wantingn to know how to format the XML for the Array content. That I have not done before buy would assume that it conforms to normal XML or Json structures.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 21 February 2020 16:37 PM UTC
AFAIK: WCF only implements XML.
  1. Helpful
  1. Mark Lee @Appeon
  2. Tuesday, 25 February 2020 08:05 AM UTC
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.