Mono WCF NetTcp 服务一次只需要一个客户端
在尝试在 Mono 中构建客户端-服务器 WCF 应用程序时,我们遇到了一些问题。 将其简化为一个简单的示例,我们发现该服务一次只接受一个客户端。如果另一个客户端尝试连接,它将挂起,直到第一个客户端断开连接。
只需更改为 BasicHttpBinding 即可解决此问题,但我们需要 NetTcpBinding 来进行双工通信。如果在 MS .NET 下编译,也不会出现该问题。
编辑:我怀疑(并且希望不会)Mono 不支持我想做的事情。据我所知,在这种情况下,Mono 代码通常会抛出 NotImplementedException。我使用的是 Mono v2.6.4
这就是我们基本场景中服务的打开方式:
public static void Main (string[] args)
{
var binding = new NetTcpBinding ();
binding.Security.Mode = SecurityMode.None;
var address = new Uri ("net.tcp://localhost:8080");
var host = new ServiceHost (typeof(Hello));
host.AddServiceEndpoint (typeof(IHello), binding, address);
ServiceThrottlingBehavior behavior = new ServiceThrottlingBehavior ()
{
MaxConcurrentCalls = 100,
MaxConcurrentSessions = 100,
MaxConcurrentInstances = 100
};
host.Description.Behaviors.Add (behavior);
host.Open ();
Console.ReadLine ();
host.Close ();
}
客户端通道是这样获取的:
var binding = new NetTcpBinding ();
binding.Security.Mode = SecurityMode.None;
var address = new EndpointAddress ("net.tcp://localhost:8080/");
var client = new ChannelFactory<IHello> (binding, address).CreateChannel ();
据我所知这是一个 Simplex 连接,不是吗?
契约很简单:
[ServiceContract]
public interface IHello
{
[OperationContract]
string Greet (string name);
}
服务实现没有 ServiceModel 标签或属性。
我将根据需要更新详细信息。
While trying to build a client-server WCF application in Mono we ran into some issues.
Reducing it to just a bare example we found that the service only accepts one client at a time. If another client attempts to connect, it hangs until the first one disconnects.
Simply changing to BasicHttpBinding fixes it but we need NetTcpBinding for duplex communication. Also the problem does not appear if compiled under MS .NET.
EDIT: I doubt (and hope not) that Mono doesn't support what I'm trying to do. Mono code usually throws NotImplementedExceptions in such cases as far as I noticed. I am using Mono v2.6.4
This is how the service is opened in our basic scenario:
public static void Main (string[] args)
{
var binding = new NetTcpBinding ();
binding.Security.Mode = SecurityMode.None;
var address = new Uri ("net.tcp://localhost:8080");
var host = new ServiceHost (typeof(Hello));
host.AddServiceEndpoint (typeof(IHello), binding, address);
ServiceThrottlingBehavior behavior = new ServiceThrottlingBehavior ()
{
MaxConcurrentCalls = 100,
MaxConcurrentSessions = 100,
MaxConcurrentInstances = 100
};
host.Description.Behaviors.Add (behavior);
host.Open ();
Console.ReadLine ();
host.Close ();
}
The client channel is obtained like this:
var binding = new NetTcpBinding ();
binding.Security.Mode = SecurityMode.None;
var address = new EndpointAddress ("net.tcp://localhost:8080/");
var client = new ChannelFactory<IHello> (binding, address).CreateChannel ();
As far as I know this is a Simplex connection, isn't it?
The contract is simply:
[ServiceContract]
public interface IHello
{
[OperationContract]
string Greet (string name);
}
Service implementation has no ServiceModel tags or attributes.
I'll update with details as required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经尝试过这个问题了,它看起来确实像一个 Mono bug。
我正在移植一个 WCF 应用程序以在 Mono 中运行。我玩过一些 NetTcpBinding 的东西,但我没有尝试过这种情况(与 Mono 托管的服务主机的多个连接)。然而现在我尝试了一下,我能够在 2.6 和最新的每日包中重现。
不过,它确实可以在 .NET 中运行。 Mono 和 .NET 之间的任何行为差异都被归类为错误。您应该使用测试用例将其记录在 Bugzilla 上,我也会将其发布在 Mono 新闻列表中。
祝你好运。
I've played around with this a bit, and it definitely looks like a Mono bug.
I'm porting a WCF application to run in Mono at the moment. I had played with some NetTcpBinding stuff, but I hadn't tried this scenario (multiple connections to a Mono-hosted service host). However now I try it out, I'm able to reproduce - both in 2.6 and the latest daily package.
It does work in .NET, however. Any difference in behavior between Mono and .NET is classed as a bug. You should log it on Bugzilla with a test case, I would also post in the Mono newslist.
Good luck.
绝对是一个错误。我想知道是否有一个版本可以正常工作...
我已将其发布在 Novell Bugzilla,如果您对其进展感兴趣。
Definately a bug. I'm wondering if there was a version it was working correctly...
I've posted it at Novell Bugzilla, if you are interested in its progress.