@Cristian_Negulescu I’ve prepared C# code to invoke it in “Invoke code activity” basic on this link: c# - Client to send SOAP request and receive response - Stack Overflow :
C# Code for GET SOAP request using HttpWebRequest:
// XML Soap Envelope Document
System.Xml.XmlDocument soapDoc = new XmlDocument();
soapDoc.LoadXml(soap_body);
// Request
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("SOAPAction", action);
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Accept = "text/xml";
request.Method = "GET";
// Insert Soap Envelope Into WebRequest
using (System.IO.Stream stream = request.GetRequestStream())
{
soapDoc.Save(stream);
}
// Begin async call to web request.
System.IAsyncResult asyncResult = request.BeginGetResponse(null, null);
// Suspend this thread until call is complete.
asyncResult.AsyncWaitHandle.WaitOne();
// Fet the response from the completed web request.
using (System.Net.WebResponse response = request.EndGetResponse(asyncResult))
{
using (System.IO.StreamReader rd = new StreamReader(response.GetResponseStream()))
{
soap_result = rd.ReadToEnd();
}
}
Variables:
var action = ""
var url = "https://url.com/xxx/services/orders2" (endpoint of web service)
var soap_body = "
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ord="http://endpoint.com/order">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Timestamp wsu:Id="TS-xxxxxxlWdEp6NXhaRS9UeGVyY3VKUT09">
<wsu:Created>2021-03-15T09:19:10.575Z</wsu:Created>
<wsu:Expires>2021-03-15T09:19:20.575Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-xxxxxxlWdEp6NXhaRS9UeGVyY3VKUT09">
<wsse:Username>service_login</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-usernametoken-profile-1.0#PasswordDigest">xxxxxxM0NjFmMDlhOTliODE2ZWYwM2Q4YTA5YzQyODFiZDJlZjkxZg==</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soapmessage-security-1.0#Base64Binary">xxxxxxlWdEp6NXhaRS9UeGVyY3VKUT09</wsse:Nonce>
<wsu:Created>2021-03-15T09:19:10.575Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ord:getDictionary>
<operatorId>1234</operatorId>
<slownik>orderStatus</slownik>
</ord:getDictionary>
</soapenv:Body>
</soapenv:Envelope>"
Where:
wsu:Id="TS-xxxxxx” and wsu:Id="UsernameToken-xxxxxx”
have “xxxxxxlWdEp6NXhaRS9UeGVyY3VKUT09” equals nonce with is
Base64String(New Microsoft.Web.Services3.Security.Nonce(16))
wsse:Password
have “xxxxxxM0NjFmMDlhOTliODE2ZWYwM2Q4YTA5YzQyODFiZDJlZjkxZg==” equals
Base64 (SHA1 (nonce_base64string + date_wsu_Created + password))
I have error while invoking code:
Exception (click to expand)
RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> RemoteException wrapping System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type.
at System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream)
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at UiPath.CodeRunner.UiPathCodeRunner_b80cb45c28f94a5f890e0ccd3f111b2b.Run(String url,
String action,
String soap_body,
String soap_result)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target,
Object[] arguments,
Signature sig,
Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object[] parameters,
Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr,
Binder binder,
Object[] parameters,
CultureInfo culture)
at System.RuntimeType.InvokeMember(String name,
BindingFlags bindingFlags,
Binder binder,
Object target,
Object[] providedArgs,
ParameterModifier[] modifiers,
CultureInfo culture,
String[] namedParams)
at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object[] args)
at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode,
List`1 inArgs,
IEnumerable`1 imps,
Object[] args)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance,
ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)
Below the correct transmission of the header (from the documentation of service provider) for POST service:
Encoding: UTF-8
Http-Method: POST
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:xxxxxx65-d7d2-44c5- ae3c-280f9e3c4493+id=1";start-info="text/xml"
Headers: {accept-encoding=[gzip, deflate], Content-Length=[1922], contenttype=[ multipart/related;type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:xxxxxx65-d7d2-44c5- ae3c-280f9e3c4493+id=1";start-info="text/xml"], Expect=[100-continue], host=[xxxmsp. provider.com], MIME-Version=[1.0], SOAPAction=[""]}
Payload:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:obj="http://endpoint.com/object">
<soapenv:Header>
<wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-secext-1.0.xsd' xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
<wsu:Timestamp wsu:Id='TS-11b7d3261c994de099eb8c431b33947b'>
<wsu:Created>2019-09-06T12:09:15.604Z</wsu:Created>
<wsu:Expires>2019-09-06T12:09:25.619Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id='UsernameToken-238be95be3bf445fb8534666a7a8693c'>
<wsse:Username>***login***</wsse:Username>
<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-usernametoken-profile-1.0#PasswordDigest'>***Base64 (SHA-1 (nonce + created + password) )***</wsse:Password>
<wsse:Nonce EncodingType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soapmessage-security-1.0#Base64Binary'>***Base64 nonce***</wsse:Nonce>
<wsu:Created>2019-09-06T12:09:15.604Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<obj:getDictionary>
<objectDictionaryType>CATEGORY</objectDictionaryType>
<operator>
<id>?</id>
<name>?</name>
<surname>?</surname>
</operator>
</obj:getDictionary>
</soapenv:Body>
</soapenv:Envelope>
Where am I making a mistake?