wcf 服务端点 null
我的 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能在 wcf 类库中拥有 app.config 并期望 WCF 从中读取设置。这没有道理。配置文件(例如 app.config)在最终的可执行应用程序项目(例如控制台应用程序、WinForms、WPF...)中定义。或者,如果它是一个 Web 应用程序,您可以使用 web.config。但是类库没有 app.config 这样的东西。因此,您可能需要使用类库将此 WCF 配置包含在应用程序的 app/web.config 中。
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.
您已为 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.
我刚刚注意到 svcutil 在 wcf 客户端项目中生成错误端点。这里
不是我的
net.tcp
端点。我还观察到这是因为
如果我从元数据生成此文件,例如:
那么它工作正常(在应用程序配置中描述正确) net.tcp 端点)
有人知道为什么 svcutil 与 *.dll 的配合会出错吗?
I just noticed that svcutil generates bad endpoint in wcf client project. There's
instead of my
net.tcp
endpoint.I also observed that's because of generation of
ProxyFile.cs
andApp.config
fromIf I generate this files from metadata like:
then it works fine (in App config is described correct net.tcp endpoint)
Does anyone knows why cooperation svcutil with *.dll goes wrong?