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:
My question is: How to add soap message header in powerbuilder before calling the method AUEAuthenticateUser.
Regards
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;
}
}
}
}