【问题标题】:wcf multiple endpoints with a single addresswcf 具有单个地址的多个端点
【发布时间】:2013-04-03 01:23:19
【问题描述】:

我已将大量 wcf 服务导入我的应用程序。 例如

<endpoint address="http://localhost:1044/PersonSearchWebService.svc" behaviorConfiguration="ClientBehavior"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPersonSearchWebService"
            contract="WSPersonSearch.IPersonSearchWebService" name="BasicHttpBinding_IPersonSearchWebService" />
        <endpoint address="http://localhost:1044/TransferService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITransferService"
            contract="WSFileTransfer.ITransferService" name="BasicHttpBinding_ITransferService" />
        <endpoint address="http://localhost:1044/ScannedFileSearchWebService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IScannedFileSearchWebService"
            contract="WSScannedFileSearch.IScannedFileSearchWebService"
            name="BasicHttpBinding_IScannedFileSearchWebService" />

它们都共享相同的服务器地址。 我可以将它们提取到一个变量中,因此当我移动到实时服务器时,我只需在一个空间中修改配置?

谢谢

【问题讨论】:

    标签: wcf


    【解决方案1】:

    您可以在服务配置中定义一个基地址,然后根据该基地址在端点中使用相对地址:

    <service name=".....">
       <host>
          <baseAddresses>
             <add baseAddress="http://localhost:1044/" />
          </baseAddresses>
       </host>
    
       <endpoint name="BasicHttpBinding_IPersonSearchWebService"
           address="PersonSearchWebService.svc" 
           behaviorConfiguration="ClientBehavior"
           binding="basicHttpBinding" 
           bindingConfiguration="BasicHttpBinding_IPersonSearchWebService"
           contract="WSPersonSearch.IPersonSearchWebService"  />
    
        <endpoint name="BasicHttpBinding_ITransferService" 
            address="TransferService.svc"
            binding="basicHttpBinding"  
            bindingConfiguration="BasicHttpBinding_ITransferService"
            contract="WSFileTransfer.ITransferService" />
    
        <endpoint name="BasicHttpBinding_IScannedFileSearchWebService"
            address="ScannedFileSearchWebService.svc"
            binding="basicHttpBinding" 
            bindingConfiguration="BasicHttpBinding_IScannedFileSearchWebService"
            contract="WSScannedFileSearch.IScannedFileSearchWebService" />
    </service>
    

    更新:很遗憾,此功能仅适用于服务器端 - 客户端配置没有等效功能。

    在客户端上,您需要完整地拼出所有 URL - 即使它们共享,例如服务器名称和端口。

    【讨论】:

    • 对不起,我应该说我只想做这个客户端。我无权访问服务器配置
    • @Crudler:客户端没有等效项 - 抱歉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多