1

I need a way to find the operations in a SOAP web service using the WSDL of the web service.

1
  • While this may be useful information, the solution should not go into the question, rather you should express the problem in the question and put the solution into an answer.
    – Armali
    Sep 21, 2018 at 12:32

1 Answer 1

1

You may use a public wsdl url such as http://www.thomas-bayer.com/axis2/services/BLZService?wsdl or https://www.lb.lt/webservices/ExchangeRates/ExchangeRates.asmx?WSDL for testing. The solution is as follows: 1) get the contents of the wsdl url. 2) Parse the wsdl xml for the operations. The code is as follows.

public string[] GetOperations(string wsdlURL)
{

    //string httpResponseMessage;
    List<string> sList = new List<string>();
    string[] s = { };
    string result = GetWSDLContent(wsdlURL);
    XmlDocument doc = new XmlDocument();
        doc.LoadXml(result);

    var nsmgr = new XmlNamespaceManager(doc.NameTable);
    nsmgr.AddNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    var nl = doc.SelectNodes("//wsdl:portType/wsdl:operation", nsmgr);
    for (var i=0; i<nl.Count; i++ ) 
    {
        sList.Add(nl[i].Attributes["name"].Value.ToString());
    }
    s = sList.ToArray();
    return s;
}
public string GetWSDLContent(string wsdlURL)
{
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(wsdlURL);
    myRequest.Method = "GET";
    WebResponse myResponse = myRequest.GetResponse();
    StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
    string result = sr.ReadToEnd();
    sr.Close();
    myResponse.Close();
    return result;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.