C# wcf服务端点为空

C# wcf服务端点为空,c#,.net-4.0,wcf,wcf-endpoint,C#,.net 4.0,Wcf,Wcf Endpoint,我的wcf服务库中有此App.config: <?xml version="1.0"?> <configuration> <appSettings> <add key="addr" value="net.tcp://localhost:22222/AdministrationService/"/> </appSettings> <system.serviceModel> <services&

我的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>
应用程序似乎不支持此tcp.net端点。为什么?

我的wcf服务库中有此App.config


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

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


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

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

<endpoint binding="basicHttpBinding"
          bindingConfiguration="DefaultBinding_IAdministration" 
          contract="IAdministration" 
          name="DefaultBinding_IAdministration_IAdministration" />"
如果我从元数据生成此文件,如:

svcutil net.tcp://localhost:8080/AdministrationService/mex /language:C# /out:ProxyFile.cs /config:App.config
然后它工作正常(应用程序配置中描述了正确的net.tcp端点)


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

-1:我相信你。@Peter K.,你如何告诉WCF使用这个自定义app.config文件中定义的设置,而不是WCF期望设置的位置=>这才是真正的app.config,为应用程序定义的应用程序?我将其放入wcf服务库中,并将其放在承载此服务的控制台应用程序中-没有任何内容changed@Saint,那么,也许显示您的代码也会有所帮助。您只发布了一些
app.config
,不清楚您在哪里部署的。。。我们甚至还不知道你是如何尝试公开/使用这项服务的。@Darin:我同意这些设置需要在使用它们的应用程序的最终配置文件中。您的声明
类库中不能有app.config
是错误的,或者充其量是误导性的。您在客户端中指定了端点地址吗?@Reniuz我在客户端中使用svcutil生成app.config…但我注意到我得到的是“”而不是我的net.tcp端点。为什么?我不是100%确定,但也许你需要在ServiceBehavior中添加
,Kiran Mothe,我做了,但没有任何改变。在下面向Darin Dimitrov和@Peter K.展示我的评论。
svcutil WcfServiceLibrary.dll
svcutil net.tcp://localhost:8080/AdministrationService/mex /language:C# /out:ProxyFile.cs /config:App.config