Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Absent Member.. vzamoraz Absent Member..
Absent Member..
153 views

ST/UFT support tip: How to Modify A SOAP Security Header at Runtime

It is possible to modify the security header of a SOAP request at runtime using the "AfterProcessRequestSecurity" event handler.

 

Given the following SOAP envelope:

<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
<Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-5236f4b9-aa81-497e-812c-b975e0c8feb2">
<wsse:Username>adam</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">****</wsse:Password>
<wsu:Created>2014-01-29T19:46:25Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</Header>
<Body>
<HelloWorld xmlns="http://www.hp.com/" />
</Body>
</Envelope>

 

 

This example will change the Username of the security header. There are two ways to approach this. One is a direct string find and replace, the other is through the XML API.

public void StServiceCallActivity10_OnAfterProcessRequestSecurity(object sender, HP.ST.Ext.WebServicesActivities.ActivityProcessXmlMessageEventArgs args)
{
// these two lines demonstrate how to perform a string replace
//String s = args.Message.InnerXml.Replace("<wsse:Username>adam</wsse:Username>", "<wsse:Username>New Name</wsse:Username>");
//args.Message.InnerXml = s;

// modify the XML using an XML API
XmlDocument xmlDocument = args.Message;
XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(xmlDocument.NameTable);
xmlnsManager.AddNamespace("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
xmlnsManager.AddNamespace("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
xmlDocument.SelectSingleNode("//wsse:Username", xmlnsManager).InnerText = "New Name";
args.Message = xmlDocument;
}

 

You can finde this information and related topics on this Kbarticle.

 

HP support

If you find that this or any post resolves your issue, mark it as an accepted solution.

 

Note: The Opinions expressed in my post are mine alone, and do not reflect the opinions of my employer. No warranties express or implied for any answered posted.

Labels (1)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.