如何从 Web 服务的 URL 获取 wsdl 文件



我想获取Web服务的WSDL文件,我唯一拥有的是它的URL(如webservice.example/foo)。

如果我直接使用 URL,则只会传递错误响应。

通过在 URL 后加上 ?WSDL

例如,如果网址是:

http://webservice.example:1234/foo

您使用:

http://webservice.example:1234/foo?WSDL

并且 wsdl 将被交付。

从 Web 服务 URL 获取WSDLWeb Service Description Language)。

可以从 SOAP Web 服务:

http://www.w3schools.com/xml/tempconvert.asmx

要获得 WSDL,我们只需要添加 ?WSDL ,例如:

http://www.w3schools.com/xml/tempconvert.asmx?WSDL

只有当

Web 服务配置为提供 WSDL 时,才有可能获取它。因此,您必须指定一个服务行为并启用httpGetEnabled:

<serviceBehaviors>
    <behavior name="BindingBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
</serviceBehaviors>

如果Web服务只能通过https访问,则必须启用httpsGetEnabled而不是httpGetEnabled。

若要使用 Visual Studio 的开发人员命令提示符从 url 下载 wsdl,请在管理员模式下运行它并输入以下命令:

 svcutil /t:metadata http://[your-service-url-here]

现在,您可以根据需要在项目中使用下载的 wsdl。

  1. 探索网址 + ?wsdl:

    http://localhost:1234/sevice.aspx?WSDL

  2. 右键单击该页面,然后选择另存为...

  3. 选择 XML 格式,然后单击保存。

最新更新