0

我的 wcf 服务库中有这个 App.config:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="addr" value="net.tcp://localhost:22222/AdministrationService/"/>
  </appSettings>
  <system.serviceModel>
    <services>
      <service name="Watchman.WcfService.AdministrationService" behaviorConfiguration="MyBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:22222/AdministrationService/"/>
          </baseAddresses>
        </host>
        <endpoint name="Ep1" address="net.tcp://localhost/AdministrationService/" binding="netTcpBinding" bindingConfiguration="DuplexBinding" contract="Watchman.WcfService.Interfaces.IAdministration"/>
        <endpoint name="mex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehavior">
          <serviceThrottling maxConcurrentSessions="10000"/>
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/AdministrationService/Ep1/wsdl"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <netTcpBinding>
        <binding name="DuplexBinding" sendTimeout="00:00:01">
          <reliableSession enabled="true"/>
          <security mode="None"/>
        </binding>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>

</configuration>

但我得到了错误:

"The Address property on ChannelFactory.Endpoint was null.  The ChannelFactory's Endpoint must have a valid Address specified."

似乎应用程序没有这个 tcp.net 端点。为什么?

4

3 回答 3

1

我的 wcf 服务库中有这个 App.config

您不能在 wcf 类库中有 app.config 并期望 WCF 从中读取设置。这没有意义。配置文件如 app.config 定义在最终的可执行应用程序项目(如控制台应用程序、WinForms、WPF...)中。或者,如果它是一个 Web 应用程序,您可以使用 web.config。但是类库中没有 app.config 之类的东西。因此,您可能需要使用您的类库在应用程序的 app/web.config 中包含此 WCF 配置。

于 2011-09-08T19:49:39.340 回答
0

您已为 net.tcp 指定了基地址,因此 net.tcp 端点上的地址变为相对地址。因此,端点的地址实际上变成了 net.tcp://localhost:22222/AdministrationService/localhost/AdministrationService/。

将端点上的地址更改为相对地址,并使用 svcutil 重新生成代理类。

于 2011-09-09T13:01:29.770 回答
0

我刚刚注意到 svcutil 在 wcf 客户端项目中生成了错误的端点。有

<endpoint binding="basicHttpBinding"
          bindingConfiguration="DefaultBinding_IAdministration" 
          contract="IAdministration" 
          name="DefaultBinding_IAdministration_IAdministration" />"

而不是我的net.tcp端点。

ProxyFile.cs我还观察到这App.config是因为

svcutil WcfServiceLibrary.dll

如果我从元数据生成这些文件,例如:

svcutil net.tcp://localhost:8080/AdministrationService/mex /language:C# /out:ProxyFile.cs /config:App.config

然后它工作正常(在应用程序配置中描述了正确的 net.tcp 端点)

有谁知道为什么与 *.dll 合作 svcutil 会出错?

于 2011-09-11T10:56:26.590 回答