在 WCF Web 服务的 WSDL 中提供不同的端点地址 [英] Supply a different endpoint address in the WSDL of a WCF web service
问题描述
我有一个相当标准的 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>
(无聊的部分省略)
我正在寻求一种快速且肮脏的方法来将生成的 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
最简单的方法是什么?
推荐答案
你可以看看以下几种方法:
There are several approaches you could look at:
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屋!