如何配置另一个WCF服务库中引用的WCF服务的URL

时间:2014-03-05 11:30:23

标签: c# wcf

这很难解释所以请让我澄清一些不清楚的事情。

我有3个WCF Web服务库和3个主机应用程序,我将其称为Service1Service2Service3。 Service2属于同一解决方案,但目前与此问题无关。

Service1引用Service3主机应用程序。编译完成后,我无法在Service3中看到为Service1配置网址的任何方法。

我希望它在Service1主机应用程序的配置中。这可能吗?我不敢相信这是在DLL中硬编码的吗?

Service1 Library App.Config:

    <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="Service3Data" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://MyHost/gws/GService3.svc/gwd"
    binding="basicHttpBinding" bindingConfiguration="Service3Data"
    contract="GServices3.IGws" name="Service3Data" />
</client>
<services>
  <service name="MyNameSpace.Business.WebServices.Service1">
    <endpoint address="" binding="basicHttpBinding" contract="MyNameSpace.Business.WebServices.IService1">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/Design_Time_Addresses/MyNameSpace.Business.WebServices/Service1/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Service1主机应用程序Web.Config(以及我需要为Service3配置URL的地方):

 <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="Service1Binding" openTimeout="00:10:00" maxBufferPoolSize="2147483646"
      maxBufferSize="2147483646" maxReceivedMessageSize="2147483646">
      <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646"
        maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="MyNameSpace.Business.WebServices.Service1">
    <endpoint address="bwd" binding="basicHttpBinding" bindingConfiguration="Service1Binding"
      name="BWData" contract="MyNameSpace.Business.WebServices.IService1" />
    <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
      contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

1 个答案:

答案 0 :(得分:1)

为WCF服务创建代理时,始终可以将<system.serviceModel>部分添加到主程序集并配置其中的所有设置(包括您为其创建代理的服务的URL)。 / p>

如果在库装配中添加代理,仍可以将<system.serviceModel>添加到主(可执行文件/ Web主机/等)程序集中。

您需要将<client>部分从库配置复制到主机应用程序配置(连同其绑定和可能的其他元素)。