WCF:修复使用 externalMetadataLocation 时的端点地址 [英] WCF: Fix the Endpoint Address When Using externalMetadataLocation

查看:27
本文介绍了WCF:修复使用 externalMetadataLocation 时的端点地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WCF 允许您指定应与服务一起发布的外部 WSDL 文件,而不是 WCF 生成的 WSDL.在 WSDL 优先的设计方法中,发布源 WSDL 而不是生成的 WSDL 更有意义.

WCF allows you to specify an external WSDL file that should be published with the service rather than WCF's generated WSDL. In a WSDL-first design approach, it makes a lot of sense to publish the source WSDL rather than the generated WSDL.

这是使用 externalMetadataLocation 设置的:

This is set using the externalMetadataLocation:

<serviceBehaviors>
  <behavior>
    <serviceMetadata httpGetEnabled="true" externalMetadataLocation="path_to_my_wsdl.wsdl"/>
    <serviceDebug includeExceptionDetailInFaults="false"/>
  </behavior>
</serviceBehaviors>

我遇到的问题是,当我这样做时,它直接服务于 WSDL,它具有错误的端点地址.我希望在运行时将端点地址替换为服务的真实端点地址(这将因部署位置而异).

The problem I'm encountering is that when I do this, it serves the WSDL straight-up, which has the wrong endpoint address. I want the endpoint address to be replaced at run-time with the real endpoint address of the service (which will differ depending on where it is deployed).

有没有简单的方法可以做到这一点?

Is there an easy way to do this?

推荐答案

我绝不是 WCF 专家,但您不能通过在配置文件 (web.config) 的端点上指定它来实现这一点,例如例子:

I'm in no way a WCF expert but can't you do this by specifying it on the endpoint in the config file (web.config), for example:

<system.serviceModel>
    <services>
        <service>
            <endpoint 
                listenUri="https://yourdomainname.com/servicename.svc"
                address="https://yourdomainname.com/servicename.svc">

注意:listenUri"是物理地址,端点address"是逻辑地址.IE.listenUri"是服务真正所在的位置,端点是客户端将要求的.

Note: "listenUri" is the physical address and the endpoint "address" is the logical address. Ie. "listenUri" is where the service really is and endpoint is what the client will be asking for.

如果它们相同,我相信您不需要 listenUri.

If they are the same you don't need listenUri I believe.

这篇关于WCF:修复使用 externalMetadataLocation 时的端点地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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