简体   繁体   English

ASMX Web服务的自定义WSDL

[英]Custom WSDL for an ASMX Web Service

Is it possible to use a custom WSDL with a .NET WebService? 是否可以将自定义WSDL与.NET WebService一起使用? I would like to use a custom WSDL with my .NET WebService instead of the one generated by .NET as part of my WebService. 我想在.NET WebService中使用自定义WSDL,而不是.NET生成的自定义WSDL作为WebService的一部分。

Actually there is a way to do this: You can create your own WSDL (ie removing methods you don't want to publish) and then make it available at a dedicated spot, this allows users to bind to it as normal. 实际上有一种方法可以做到这一点:您可以创建自己的WSDL(即删除您不想发布的方法),然后在专用位置使其可用,这允许用户正常绑定它。

To prevent users from just retrieving the default WSDL ( foo.asmx?wsdl ) you have to flip a switch in the web.config of your web service: 要防止用户只检索默认WSDL( foo.asmx?wsdl ),您必须在Web服务的web.config中翻转一个开关:

  <webServices>
    <protocols>
      <remove name="Documentation"/>
    </protocols>
  </webServices>

From the relevant MSDN section : 相关的MSDN部分

Note Removing the Documentation protocol also disables WSDL file generation for any XML Web services within the Web application. 注意删除文档协议还会禁用Web应用程序中任何XML Web服务的WSDL文件生成。 This prevents clients from generating a proxy class unless a custom WSDL file is created and provided for them. 这可以防止客户端生成代理类,除非为它们创建并提供了自定义WSDL文件。

I presume that what you want is to replace the file generated by .NET when your service is hit with the "?wsdl" query string on it. 我假设您想要的是当您的服务被命中时使用“?wsdl”查询字符串来替换.NET生成的文件。

No, there is no direct way to do this. 不,没有直接的方法来做到这一点。 Instead, simply place your .wsdl on a web site, and tell the consumers of your service to get it from there. 相反,只需将.wsdl放在网站上,并告诉消费者您的服务是从那里获得的。 There is no standard saying that "?wsdl" is the only way to get a WSDL file. 没有标准说“?wsdl”是获取WSDL文件的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM