Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何配置在另一个WCF服务库中引用的WCF服务的URL_C#_Wcf - Fatal编程技术网

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

C# 如何配置在另一个WCF服务库中引用的WCF服务的URL,c#,wcf,C#,Wcf,这很难解释,所以请让我澄清任何不清楚的地方 我有3个WCF web服务库和3个主机应用程序,我将它们称为Service1,Service2和Service3。Service2位于同一解决方案中,但目前与此问题无关 Service1引用Service3主机应用程序。编译后,我无法在Service1中为Service3配置URL 我希望它位于Service1主机应用程序的配置中。这可能吗?我不敢相信这是硬编码的DLL Service1 Library App.Config: <syst

这很难解释,所以请让我澄清任何不清楚的地方

我有3个WCF web服务库和3个主机应用程序,我将它们称为
Service1
Service2
Service3
。Service2位于同一解决方案中,但目前与此问题无关

Service1
引用
Service3
主机应用程序。编译后,我无法在
Service1
中为
Service3
配置URL

我希望它位于
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的位置):



为WCF服务创建代理时,始终可以向主程序集添加
部分,并在其中配置所有设置(包括为其创建代理的服务的URL)

如果在库程序集中添加代理,仍然可以将
添加到主(可执行文件/web主机/etc)程序集中


您需要将
部分从库配置复制到主机应用程序配置(及其绑定和其他元素)。

当您说“Service1引用Service3主机应用程序”时,您的意思是在Service1中为Service3创建代理吗?@Szymon对不起,是的,这就是我的意思。好的,因此,添加代理意味着您应该在Service1的配置文件中也有一个条目,并且您应该能够在其中设置URL。您是说我可以在Web.config for Service1主机应用程序中添加Service3的代理?是的,没错。您始终可以为代理添加配置,即使您在其他地方(在另一个程序集中)生成它。配置将自动使用。我更新了我的答案。
 <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" />