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
K2 Automated Testing Software
BenchQA allows full test automation of K2, including fully automated K2 SmartForms and K2 Workflow testing. It promotes test driven development for K2 and ensures continued quality assurance for K2 solutions. Easily apply changes to test cases to accommodate changes to K2 apps and ensure all apps are regression tested to avoid defects and assure continuous quality.
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 –
- 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.