C# 带有 NetTcpBinding 的 WCF 服务库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1297756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF Service Library with NetTcpBinding
提问by Josh
I'm having a tough time with NetTcpBinding.
我在使用 NetTcpBinding 时遇到了困难。
When I run my WCFservice,I get this:
当我运行我的 WCFservice 时,我得到了这个:
System.InvalidOperationException: Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName)
at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
I'm getting this when I run the application by default using WCFSvcHost. There's no extra code.Just the default code of any new wcf service. All I wanted to do was change the binding to tcp.
当我默认使用 WCFSvcHost 运行应用程序时,我得到了这个。没有额外的代码。只是任何新 wcf 服务的默认代码。我想要做的就是将绑定更改为 tcp。
How do I solve this problem?
我该如何解决这个问题?
Edit: Here's my WCF's App.config
编辑:这是我的 WCF 的 App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" transferMode="Streamed" portSharingEnabled="false">
<reliableSession enabled="true" />
<security mode="None">
<transport clientCredentialType="None" protectionLevel="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="Service" binding="netTcpBinding" bindingConfiguration="tcpBinding"
name="testTcp" contract="WcfServiceLibrary1.IService1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
采纳答案by Brian
In this section
在这个部分
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/.../" />
</baseAddresses>
</host>
add a net.tcp:// base address.
添加 net.tcp:// 基地址。
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/" />
<add baseAddress="net.tcp://localhost"/>
</baseAddresses>
</host>
回答by Helder
I'm sure by now you've fixed the issue, but it really is nothing to do with baseAddresses which is what all the bullentin boards lead you to. I found the answer at http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c9f8d99d-89ee-4573-8528-a21b047bad11. Assuming you are using IIS 7.x: right click the virtual directory/application in IIS, select Manage application -> Advanced settings. In the 'Enabled Protocols' section add net.tcp, e.g.: http,net.tcp. This is necessary even if you added this protocol already at the site level.
我确定现在您已经解决了这个问题,但这与所有公告板引导您的 baseAddresses 确实无关。我在http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c9f8d99d-89ee-4573-8528-a21b047bad11找到了答案。假设您使用的是 IIS 7.x:右键单击 IIS 中的虚拟目录/应用程序,选择管理应用程序 -> 高级设置。在“启用的协议”部分添加 net.tcp,例如:http,net.tcp。即使您已经在站点级别添加了此协议,这也是必要的。
回答by Sean M
- Verify the Net.Tcp Port Sharing Service is started on the machine
- Verify the configuration netTcpBinding portSharingEnabled attribute is true. (In WCF4 you don't need to provide a name on the binding element if you want this binding specification to be the default for net.tcp)
- 验证机器上启动了 Net.Tcp 端口共享服务
- 验证配置 netTcpBinding portSharingEnabled 属性为 true。(在 WCF4 中,如果您希望此绑定规范成为 net.tcp 的默认值,则无需在绑定元素上提供名称)
回答by Ranjith
Configure net.tcp binding in your IIS site and set enabled protocol as "http,net.tcp using advanced setting".It should work
在您的 IIS 站点中配置 net.tcp 绑定并将启用的协议设置为“使用高级设置的 http,net.tcp”。它应该可以工作
回答by Kellen
You can share ports, it's not too hard.
您可以共享端口,这并不难。
Make sure when selecting enabled protocols in IIS (right click on site -> Manage Web Site -> Advanced Settings) that you DO NOT USE SPACES. If you have "http, net.tcp" instead of "http,net.tcp" it will not work, and instead give you this exact error.
确保在 IIS 中选择启用的协议(右键单击站点 -> 管理网站 -> 高级设置)时不要使用空格。如果你有“http,net.tcp”而不是“http,net.tcp”,它就不会工作,而是给你这个确切的错误。
More information here: http://www.weeksofprogramming.com/post/Could-not-find-a-base-address-Check-for-spaces-in-IIS7.aspx
更多信息:http: //www.weeksofprogramming.com/post/Could-not-find-a-base-address-Check-for-spaces-in-IIS7.aspx