2

我已经在我的应用程序中导入了很多 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" />

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

谢谢

4

1 回答 1

4

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

<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——即使它们共享例如服务器名称和端口。

于 2013-04-02T17:14:18.780 回答