在WCF Web服务的WSDL中提供不同的端点地址 [英] Supply a different endpoint address in the WSDL of a WCF web service

查看:424
本文介绍了在WCF Web服务的WSDL中提供不同的端点地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当标准的WCF服务(托管在IIS7上),当用查询时生成一个相当标准的WSDL?wsdl

I have a fairly standard WCF service (hosted on IIS7) which generates a fairly standard WSDL when queried with ?wsdl:

<wsdl:definitions>
  <!-- ... -->
  <wsdl:service>
    <wsdl:port>
      <soap:address location="https://machine/virtual_dir/servicename.svc"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

(省略无聊位)

I在快速'肮脏的方式将此生成的WSDL中给出的地址更改为完全不同之后,例如:

I'm after a quick 'n dirty way to change the address given in this generated WSDL to something completely different, for example:

https://othermachine/other_dir/other_service.svc

什么是最简单的方法吗?

What is the easiest way of doing this?

推荐答案

你可以看几种方法:


  • WCF支持许多可扩展点,而WSDL的生成就是其中之一。您可以编写自己的自定义WSDL生成器并将其插入WCF

  • WCF supports a lot of extensibility points, and the generation of the WSDL is one of those. You could write your own custom WSDL generator and plug it into WCF

生成您拥有的WSDL可能更简单,然后手动调整它,以及将该WSDL文件放在某处并将其配置为提供服务(而不是WCF在运行时生成WSDL,当请求时)

the probably easier way would be to generate the WSDL you have, then tweak it manually, and put that WSDL file somewhere and configure it to be served up (instead of WCF generating the WSDL at runtime, when requested to do so)

您可以使用< serviceMetadata> 行为配置选项#2:

You can configure option #2 with the <serviceMetadata> behavior:

<behaviors>
   <serviceBehaviors>
       <behavior name="StaticMetadata">
           <serviceMetadata httpGetEnabled="true"
                externalMetadataLocation="(url path to your static WSDL file)" />
       </behavior>
   </serviceBehaviors>
</behaviors>

如果这样做,并且您的服务使用此服务行为,则对WSDL或MEX的任何请求数据将路由到您提供的静态WSDL,而不是使用WCF通常提供的自动生成的WSDL。

If you do this, and your service uses this service behavior, any requests for the WSDL or for MEX data will be routed to that static WSDL you've provided, instead of using the auto-generated WSDL that WCF would normally supply.

这篇关于在WCF Web服务的WSDL中提供不同的端点地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆