1. Ahmed Abdalla
  2. PowerBuilder
  3. Tuesday, 6 February 2018 05:31 AM UTC

Dear Sir,

I am trying to consume a webservice using powerbuilder 2017R2. I have the code in C# which consume the same webservice and trying now to do consume it in Powerbuilder. I have created a WCF proxy to access the web service and was able to connect. However, in order to call any method in the webservice, I need to add soap header for the API key.  similar to the code in c#:

 //add a soap header for API Key
MessageHeader ApiMessageHeader = MessageHeader.CreateHeader("API_KEY", "http://tempuri.org", API_KEY);
                    System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(ApiMessageHeader);
string userName = "username";
string passWord = "xxxxxx.";
string Provider = "dsadsa";
//calls the authenticate user, if the authentication is successful it will assign the token variable the appropriate value         

client.AUEAuthenticateUser(userName, passWord, Provider, ref token);

--------------

so far I have write the following in Powerbuilder:

Long ll_rc, ll_ret
SoapConnection conn
basichttpbinding_iamanunionservice client
string userName = "xya", ls_result
string passWord = "ABC."
string Provider = "ddddd"
string token
//API key to be used in soap header
string API_KEY = "xxxxxxxxxxx@";
boolean lb_res, lb_res_spec
 
//tns__str_contract_importer_name ImpName[]
 
conn = Create SoapConnection
ll_rc = conn.SetBasicAuthentication ("API_KEY", "http://tempuri.org", API_KEY)
ll_rc = conn.CreateInstance (client, 'basichttpsbinding_iamanunionservice' )
 
IF ll_rc > 0 THEN
MessageBox("Error", "Cannot create instance of proxy")
return
end if
 
Try
 
client.aueauthenticateuser( userName, passWord, Provider, ref token, ref lb_res, ref lb_res_spec)
 
 
client.auegetsearchresults("SAL", "LE", -1, true)
MessageBox ("OK", "OK")
catch (SoapException e)
MessageBox("Error", e.GetMessage())
finally
Destroy Conn
End Try
 
---------------------------------------------------

My question is: How to add soap message header in  powerbuilder before calling the method AUEAuthenticateUser.

Regards

Marco Meoni Accepted Answer Pending Moderation
  1. Tuesday, 6 February 2018 07:47 AM UTC
  2. PowerBuilder
  3. # 1

Hi Hani,

the SoapClient object is limited and can’t support WS-security or extended header settings as it is based on old ASP WS technology. 

If you post your code that uses the new HTTPClient object we can try to reproduce the problem.

Best,

.m

Comment
  1. Ahmed Abdalla
  2. Tuesday, 6 February 2018 09:22 AM UTC
I am trying to configure out how yo use the httpclient object. Do I need to create Webservice Proxy?

  1. Helpful
  1. Ahmed Abdalla
  2. Tuesday, 6 February 2018 09:28 AM UTC
Here is my C# sample, note that this is a working version, I have changed the username and password so that they do not expose to public;



using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.ServiceModel;

using System.ServiceModel.Channels;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

//using WindowsFormsApplication2.cy.com.cosine.dev;

namespace WindowsFormsApplication2

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }



        private void button1_Click(object sender, EventArgs e)

        {

            //token variable to be used in soap header

            string token = "";

            //API key to be used in soap header

            string API_KEY = "HANIAPIKEY";

            //My webService client

            AmanUnionWebService.AmanUnionServiceClient client = new AmanUnionWebService.AmanUnionServiceClient();

            try

            {

                using (new OperationContextScope(client.InnerChannel))

                {



                    

                    //add a soap header for API Key

                    MessageHeader ApiMessageHeader = MessageHeader.CreateHeader("API_KEY", "http://tempuri.org", API_KEY);

                    System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(ApiMessageHeader);





                    string userName = "username";

                    string passWord = "Pssw.";

                    string Provider = "Provider";

                    //calls the authenticate user

                    //if the authentication is successful it will assign the token variable the appropriate value                   

                    client.AUEAuthenticateUser(userName, passWord, Provider, ref token);

                   

                    //add a soap header for authentication key

                    //I add my token to the soap header

                    MessageHeader AuthMessageHeader = MessageHeader.CreateHeader("AUTH_TOKEN", "http://tempuri.org", token);

                    System.ServiceModel.OperationContext.Current.OutgoingMessageHeaders.Add(AuthMessageHeader);

                    label1.Text = null;

                    DateTime date = DateTime.Today;

                    DataSet companySearchResults = client.AUEGetSearchResults("SAL", "LE", -1 );

                    if (companySearchResults.Tables.Count > 0)

                    {

                        dataGridView1.DataSource = companySearchResults.Tables[0];

                        dataGridView1.Refresh();                   

                    }



 



                }

            }

            catch (Exception ex)

            {

                var message = ex.InnerException.Message;

                label1.Text = message;

                

            }



        }



       

    }

}

  1. Helpful
There are no comments made yet.
Ahmed Abdalla Accepted Answer Pending Moderation
  1. Tuesday, 6 February 2018 07:13 AM UTC
  2. PowerBuilder
  3. # 2

The documentation of powerbuilder 2017R2 says the following:

SetRequestHeader

Description

Sets the request header.

Applies to

HTTPClient and RestClient objects

----

However, the function is not working for RestClient, and return unknown function name. 

Comment
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.