简体   繁体   English

wcf服务端点null

[英]wcf service endpoint null

I have this App.config in my wcf service library: 我的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>

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. 似乎应用程序没有此tcp.net端点。 Why? 为什么?

I have this App.config in my wcf service library 我的wcf服务库中有这个App.config

You cannot have an app.config in a wcf class library and expect WCF to read settings from it. 您不能在wcf类库中有一个app.config,并且希望WCF从中读取设置。 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, ...). 在最终的可执行应用程序项目(例如控制台应用程序,WinForms,WPF等)中定义了诸如app.config之类的配置文件。 Or if it is a web application you use a web.config. 或者,如果它是一个Web应用程序,则使用web.config。 But there is not such thing as app.config for a class library. 但是,类库没有诸如app.config这样的东西。 So you might need to include this WCF configuration in the app/web.config of the application using your class library. 因此,您可能需要使用类库将此WCF配置包括在应用程序的app / web.config中。

You have specified a base address for net.tcp, so the address on the net.tcp endpoint becomes a relative address. 您已为net.tcp指定了基地址,因此net.tcp端点上的地址成为相对地址。 So, effectively the address of the end point becomes net.tcp://localhost:22222/AdministrationService/localhost/AdministrationService/. 因此,端点的地址实际上变为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. 将端点上的地址更改为相对地址,然后使用svcutil重新生成代理类。

I just noticed that svcutil generates bad endpoint in wcf client project. 我只是注意到svcutil在wcf客户端项目中生成了错误的端点。 There's

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

instead of my net.tcp endpoint. 而不是我的net.tcp端点。

I also observed that's because of generation of ProxyFile.cs and App.config from 我还观察到这是由于生成了ProxyFile.csApp.config

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) 然后工作正常(在App config中描述了正确的net.tcp端点)

Does anyone knows why cooperation svcutil with *.dll goes wrong? 有谁知道为什么与* .dll的svcutil合作出错?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM