K2

How to integrate K2 to a Webservice that requires security headers

In this article we will see how to connect to soap webservices with security headers from K2.

At present K2 (4.6.7) doesn’t support registering the webservices with security headers as a service instance.

There is a workaround to achieve this

Create a classlibrary with the methods as below.  Create a static parametrised method ,So that we can use from workflow using code reference event.

public static string SendValues(string Parameter1,string Parameter2,string WebserviceURL,string Action)
 {
 try
 {
 httpwebrequest webrequest=httpwebrequest(string WebserviceURL,string Action);
XmlDocument soapEnvelopeXml=Createsoapxml(Parameter1,Parameter2);
PassSoapenvelopeintoWebRequest( soapEnvelopeXml,webRequest);
 return “Success”
 }
 catch(Exception ex)
 {
 return ex.message;
 }
 }

Build SOAP webservice as xml with your parameter values

public XMLDocument Createsoapxml(string Parameter1,string Parameter2)
 {
 xmldocument soapEnvelop=new xmldocument();
stringbuilder sbxml=new stringbuilder;

Build your SOAP with Envelope,Headers and body by passing the parameters as values

return soapEnvelop;
 }
public HttpWebRequest httpwebrequest(string URL,string Action)
 {
 HttpWebRequest request=(HttpWebRequest)WebRequest.Create(URL);
 request.headers.add(“soapaction”,”urn”+action);
 request.ContentType = "text/xml;charset="utf-8"";
 request.Accept = "text/xml";
 request.Method = "POST";
 return request;
 }
 PassSoapenvelopeintoWebRequest(xmldocument ,httpwebrequest)
 {
 using(stream stream=httpwebrequest .getrequeststream())
 {
 xmldocument.Save(stream)
 }
 }

You can use the above build class library dll in two ways from K2 –

  1. Using as a code reference event from workflow

a) Build the dll and add as reference to the process and check copy local , so that this dll will be copied to server while deploying to server.

b) Add code reference event and we can see the SendValues Static method and we can pass datafields as values as a parameters to this method
2. Using as a Smartobject in Smartforms or Workflow

a) build the dll and register it as a endpoint assemblies Service instance or as a custom service broker with required changes

b)generate smartobjects from service instance and use that in a smartforms or workflow

So,now you can pass the values from workflow or smartforms to Webservice with security headers.

You may also like

Leave a comment

PODCAST  |  Why you need to establish a K2 Center of Excellence today

Interview with Arno van Rooyen, CEO, Velocity