【问题标题】:wcf service endpoint nullwcf 服务端点 null
【发布时间】:2011-11-13 07:02:33
【问题描述】:

我的 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 端点。为什么?

【问题讨论】:

  • 您是否在客户端中指定了端点地址?
  • @Reniuz 我使用 svcutil 在客户端生成 app.config ......但我只是注意到我得到了“" 而不是我的 net.tcp 端点。为什么?
  • 我不是 100% 确定,但也许您需要在 serviceBehaviors 中添加 &lt;behavior name="metadataSupport"&gt;

标签: c# .net-4.0 wcf wcf-endpoint


【解决方案1】:

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

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

【讨论】:

  • @Peter K.,你将如何告诉 WCF 使用在此 custom app.config 文件中定义的设置,而不是 WCF 期望的设置 =>哪个是真正的 app.config,为应用程序定义的那个?
  • 我将它放入 wcf 服务库和托管此服务的控制台应用程序 - 没有任何改变
  • @Saint,也许显示您的代码也可能会有所帮助。你只发布了一些app.config,不清楚你在哪里部署,......我们甚至不知道(还)你是如何尝试公开/使用这项服务的。
  • @Darin:我同意这些设置需要在使用它们的应用程序的最终配置文件中。您的声明You cannot have an app.config in a class library 是错误的,或者充其量是误导性的。
【解决方案2】:

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

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

【讨论】:

  • Kiran Mothe,我做到了,但没有任何改变。在下面向 Darin Dimitrov 和@Peter K. 展示我的评论。
【解决方案3】:

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

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

而不是我的net.tcp 端点。

我还观察到这是因为 ProxyFile.csApp.config 的生成来自

svcutil WcfServiceLibrary.dll

如果我从以下元数据生成这些文件:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 2010-09-16
    • 2012-08-28
    • 2014-05-04
    • 2012-06-30
    • 2011-09-19
    相关资源
    最近更新 更多