我想要获取 Web 服务的 WSDL 文件,而我唯一拥有的就是它的 URL(如 webservice.example/foo)。
如果我直接使用 URL,则只会传递错误响应。
通过在 URL 后缀
?WSDL
如果 URL 例如:
http://webservice.example:1234/foo
您使用:
http://webservice.example:1234/foo?WSDL
wsdl 将被交付。
WSDL
(Web Service Description Language
)。可以通过 SOAP Web 服务实现:
http://www.w3schools.com/xml/tempconvert.asmx
要获取 WSDL,我们只需添加
?WSDL
,例如:
仅当 Web 服务配置为传送 WSDL 时,才可能获取 WSDL。因此,您必须指定一个 serviceBehavior 并启用 httpGetEnabled:
<serviceBehaviors>
<behavior name="BindingBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
如果网络服务只能通过 https 访问,您必须启用 httpsGetEnabled 而不是 httpGetEnabled。
要使用 Visual Studio 的开发人员命令提示符从 url 下载 wsdl,请在管理员模式下运行它并输入以下命令:
svcutil /t:metadata http://[your-service-url-here]
您现在可以根据需要在项目中使用下载的 wsdl。
探索 url + ?wsdl:
http://localhost:1234/sevice.aspx?WSDL
右键单击页面并选择另存为...
选择 XML 格式并单击“保存”。