I am trying to send a SOAP request to a web service that uses WSSE and UsernameToken for authentication. The sample query is as follows (masking confidential data):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:kas="http://webservice.com">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>abc</wsse:Username>
<wsse:CustomField>123</wsse:CustomField>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<kas:method1>
<!--Optional:-->
<method1>
<!--Optional:-->
<queryNo>12345678901</queryNo>
</method1>
</kas:method1>
</soapenv:Body>
</soapenv:Envelope>
I have generated a proxy class using WSE 3.0 and the problem is that I get the error: "Object reference not set to an instance of an object." The problematic part of my C# code is below:
queryNoSorguType q = new queryNoSorguType();
string query_parameter = query_no;
q.queryNo = query_parameter;
ResultType[] r = new ResultType[10];
UsernameToken token = new UsernameToken("abc", "123",PasswordOption.SendPlainText);
//mWebService.SetClientCredential<UsernameToken>(token);
//Policy webServiceClientPolicy = new Policy();
mWebService.RequestSoapContext.Security.Tokens.Add(token);
//mWebService.SetPolicy(webServiceClientPolicy);
//r = mWebService.documentQuerybyQueryNo(q);
System.Data.DataTable outputDataTable = new System.Data.DataTable();
//System.Data.DataRow outRow = outputDataTable.Rows.Add();
//outRow["field1"] = r;
output = outputDataTable;
I located the problematic part by systemically commenting out portions of my code. I am quite unfamiliar with web services, C# and I am actually implementing this in Blue Prism. Although this program works with SOAP web services out of the box, unfortunately it does not natively support SOAP headers.
The SOAP request works fine in SOAP UI and there are no compiler errors in Blue Prism. I tried adding the headers as instructed in the manual and on the web, but it did not work. I would appreciate it if you could point me in the right direction.
EDIT After writing, compiling a console application in Visual Studio 2017 I get the following error. As far as I understand it does not have the definitions for the headers.
Unhandled Exception: System.Web.Services.Protocols.SoapHeaderException: MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebService.queryByQueryNo(queryNoQueryType queryByQueryNo1) in C:\Users\user\source\repos\ConsoleApp1\ConsoleApp1\Web References\WebService\Reference.cs:line 1533
at ConsoleApp1.Program.Main(String[] args) in C:\Users\user\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 33