3

I m using C# and I want to check which version of SOAP a WSDL is supporting.How can I find this?

WSDL 1.1 File have following namespace in it

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

WSDL 1.2 file have following namespace in it

 xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"    

And If a file is supporting both version it can have following type of content in it

<wsdl:binding name="CustServiceSoap" type="tns:CustServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetAllCustomers">
      <soap:operation soapAction="http://tempuri.org/GetAllCustomers" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetNCustomers">
      <soap:operation soapAction="http://tempuri.org/GetNCustomers" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetRangeOfCustomers">
      <soap:operation soapAction="http://tempuri.org/GetRangeOfCustomers" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>


<wsdl:binding name="CustServiceSoap12" type="tns:CustServiceSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetAllCustomers">
      <soap12:operation soapAction="http://tempuri.org/GetAllCustomers" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetNCustomers">
      <soap12:operation soapAction="http://tempuri.org/GetNCustomers" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetRangeOfCustomers">
      <soap12:operation soapAction="http://tempuri.org/GetRangeOfCustomers" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>

Abhi
  • 5,501
  • 17
  • 78
  • 133
  • This link has some details http://stackoverflow.com/questions/736845/can-a-wsdl-indicate-the-soap-version-1-1-or-1-2-of-the-web-service. Are you looking for how to do this in WCF? – Gangadhar Apr 11 '12 at 05:22
  • I want to write a function wherein if i provides the URL of WSDL file , then it can return whether 1.1 is supported or 1.2 is supported or both are supported. This can be done I think while parsing WSDL file . – Abhi Apr 11 '12 at 05:36
  • Process the WSDL document with some XSLT. Easy, lightweight and if you ever need to change what the XSLT is finding (saved as a template) you dont need to do a full deploy. – Chris Apr 11 '12 at 06:19

2 Answers2

0
public void Foo()
{
    //var uri = new Uri("http://kozhevnikov.com/foo.asmx?WSDL");
    //var uri = new Uri("http://kozhevnikov.com/bar.svc?WSDL");

    var importer = new WsdlImporter(new MetadataExchangeClient(uri, MetadataExchangeClientMode.HttpGet).GetMetadata());
    var version = importer.ImportAllEndpoints().Aggregate(Soap.None, (v, e) => v | Parse(e.Binding.MessageVersion.Envelope));

    if (version == Soap.None)
        Console.WriteLine("Is None.");
    if (version.HasFlag(Soap.Both))
        Console.WriteLine("Has Both.");

    Console.WriteLine(version);
}

private static Soap Parse(EnvelopeVersion version)
{
    if (version == EnvelopeVersion.None)
        return Soap.None;
    if (version == EnvelopeVersion.Soap11)
        return Soap.Soap11;
    if (version == EnvelopeVersion.Soap12)
        return Soap.Soap12;
    throw new NotImplementedException(version.ToString());
}

public enum Soap
{
    None,
    Soap11,
    Soap12,
    Both = Soap11 | Soap12
}
Ilya Kozhevnikov
  • 10,242
  • 4
  • 40
  • 70
0

Despite of passing almost a decade from this question and also soap services becoming legacy, one still might need to deal with them like me!

using System.Web.Services.Description;
using System.Net.Http;
using System.Collections.Generic;
using System.Linq;

private static async Task<string[]> GetSoapVersions()
{
    var client = new HttpClient();
    var stream = await client.GetStreamAsync(WSDL_URL);

    var serviceDescription = ServiceDescription.Read(stream);

    var allVersionsCollection = new List<string>();

    foreach (Binding binding in serviceDescription.Bindings)
    {
        foreach (var extension in binding.Extensions)
        {
            if (extension is Soap12Binding)
                allVersionsCollection.Add("Soap12");
            else if (extension is SoapBinding)
                allVersionsCollection.Add("Soap11");
        }
    }

    return allVersionsCollection.Distinct().ToArray();
}
VahidShir
  • 2,066
  • 2
  • 17
  • 27