gpt4 book ai didi

c# - 以编程方式检查 WSDL 文件支持的 SOAP 版本(1.1 或 1.2 或两者)

转载 作者:行者123 更新时间:2023-12-05 08:02:05 27 4
gpt4 key购买 nike

我正在使用 C#,我想检查 WSDL 支持哪个版本的 SOAP。我如何找到它?

WSDL 1.1 文件中包含以下命名空间

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

WSDL 1.2 文件中有以下命名空间

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

如果一个文件同时支持这两个版本,它可以包含以下类型的内容

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

最佳答案

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
}

关于c# - 以编程方式检查 WSDL 文件支持的 SOAP 版本(1.1 或 1.2 或两者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10100166/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com