
Good Day,
I am trying to create a custom workflow activity that check for a cartain field on an opportunity ans if the value is correct
calls a Soap web service and sends two parameters into the method call.
My challege is the code for calling Soap within D365 Custom worfkflow ,I have not idea of the coe I should use.
Can someone please assit on how I shouold tackle the calling of the soap web service, especially how I go about coding for that.
I am in need of the code mote than anything else to perfom this action
Hi,
Use below snippet to call SOAP Service passing soap xml and soap service URL, it will return soap response as string
If your web service is WCF there is different approach to consume.
public string CallSoapService(string soapuri,string soapXml)
{
try
{
if (!string.IsNullOrEmpty(soapXml))
{
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(soapXml);
HttpWebRequest webRequest = CreateWebRequest(soapUri);
Stream stream = await webRequest.GetRequestStreamAsync();
soapEnvelopeXml.Save(stream);
WebResponse response = await webRequest.GetResponseAsync();
string soapResult = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(response.GetResponseStream());
soapResult = xmlDoc.InnerText;
serviceResponse.StatusCode = 200;
if (!string.IsNullOrEmpty(soapResult))
{
return soapResult;
}
else
{
return null;
}
}
else
{
throw new Exception("Empty XML string");
}
}
catch (WebException ex)
{
throw;
}
catch (Exception e)
{
throw;
}
}
private HttpWebRequest CreateWebRequest(string soapUri)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(soapUri);
webRequest.Headers.Add("SOAPAction", "");
webRequest.ContentType = "application/soap+xml;charset=UTF-8";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
webRequest.KeepAlive = false;
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
{
webRequest.Credentials = new NetworkCredential(_username, _password);
}
return webRequest;
}