wcf 服务端点 null

发布于 2024-12-03 15:43:48 字数 1986 浏览 0 评论 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 端点。为什么?

I have this App.config in my wcf service library:

<?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>

but I got error:

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

It seems like application doesn't this tcp.net endpoint. Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情深缘浅 2024-12-10 15:43:48

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

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

I have this App.config in my wcf service library

You cannot have an app.config in a wcf class library and expect WCF to read settings from it. It doesn't make sense. Config files such as app.config are defined in the final executable application project (such as a Console application, WinForms, WPF, ...). Or if it is a web application you use a web.config. But there is not such thing as app.config for a class library. So you might need to include this WCF configuration in the app/web.config of the application using your class library.

旧时光的容颜 2024-12-10 15:43:48

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

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

You have specified a base address for net.tcp, so the address on the net.tcp endpoint becomes a relative address. So, effectively the address of the end point becomes net.tcp://localhost:22222/AdministrationService/localhost/AdministrationService/.

Change the address on the endpoint to a relative address and re-generate the proxy class using svcutil.

梓梦 2024-12-10 15:43:48

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

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

不是我的 net.tcp 端点。

我还观察到这是因为

svcutil WcfServiceLibrary.dll

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

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

那么它工作正常(在应用程序配置中描述正确) net.tcp 端点)

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

I just noticed that svcutil generates bad endpoint in wcf client project. There's

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

instead of my net.tcp endpoint.

I also observed that's because of generation of ProxyFile.cs and App.config from

svcutil WcfServiceLibrary.dll

If I generate this files from metadata like:

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

then it works fine (in App config is described correct net.tcp endpoint)

Does anyone knows why cooperation svcutil with *.dll goes wrong?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文