Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer Service forum

Call a Soap Web service from dyanmic Custom workflow and give it Two parameters

(0) ShareShare
ReportReport
Posted on by

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

  • Suggested answer
    imayur Profile Picture
    630 on at
    RE: Call a Soap Web service from dyanmic Custom workflow and give it Two parameters

    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;
            }
    
    
    
           

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,277 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,019 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans