WCF: Fix the Endpoint Address When Using externalMetadataLocation

浪尽此生 提交于 2021-01-27 06:34:16

问题


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.

This is set using the externalMetadataLocation:

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

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?


回答1:


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">

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.

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



来源:https://stackoverflow.com/questions/4035523/wcf-fix-the-endpoint-address-when-using-externalmetadatalocation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!