Mono WCF InstanceContextMode 不起作用
我有一个如下所示的服务:
[ServiceContract(SessionMode = SessionMode.Required)]
public interface ILabListener
{
[OperationContract]
byte[] GetChallenge();
...
...
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.PerSession)]
class LabListener : ILabListener
{
private byte[] challenge;
public LabListener()
{
[challenge is initialized to random data from RNG]
File.AppendAllText(Program.LogPath, String.Format("{1} - Starting LabListener session: {2}, challenge: {3}{0}",
Environment.NewLine, DateTime.Now, OperationContext.Current.SessionId, Convert.ToBase64String(auth.Challenge.Take(16).ToArray())));
}
public byte[] GetChallenge()
{
return challenge;
}
...
...
var binding = new NetTcpBinding(SecurityMode.None);
host = new ServiceHost(typeof(LabListener), new Uri(String.Format("net.tcp://{0}:800/LabListener", Environment.MachineName)));
host.AddServiceEndpoint(typeof(ILabListener), binding, "");
...
LabListenerClient client = new LabListenerClient();
Console.WriteLine(Convert.ToBase64String(client.GetChallenge());
Console.WriteLine(Convert.ToBase64String(client.GetChallenge());
当在 Windows 上的 MS .net 中托管此服务时,每个 GetChallenge 的输出都是相同的,并且 LabListener 的构造函数仅被调用一次。
如果我在 OpenSuSE 11.3 下的 mono 2.6.7 中托管它,则会为每次调用 GetChallenge 创建一个新的 LabListener,并返回两个不同的值。
这是 Linux 上服务器上的日志输出:
2010 年 8 月 26 日 8:07:57 PM - 启动 LabListener 会话:urn:uuid:5e41d193-c723-4839-abc0-93103dbd63f1,挑战:hDPwoofYUrEjAJ1Q8cWDYw==
2010 年 8 月 26 日 8:07:57 PM - 开始 实验室监听器会话: 瓮:uuid:5e41d193-c723-4839-abc0-93103dbd63f1, 挑战:6/3M4EhiKrAMM2j47MCIpQ==
如何纠正单声道行为?
I have a service that looks like this:
[ServiceContract(SessionMode = SessionMode.Required)]
public interface ILabListener
{
[OperationContract]
byte[] GetChallenge();
...
...
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.PerSession)]
class LabListener : ILabListener
{
private byte[] challenge;
public LabListener()
{
[challenge is initialized to random data from RNG]
File.AppendAllText(Program.LogPath, String.Format("{1} - Starting LabListener session: {2}, challenge: {3}{0}",
Environment.NewLine, DateTime.Now, OperationContext.Current.SessionId, Convert.ToBase64String(auth.Challenge.Take(16).ToArray())));
}
public byte[] GetChallenge()
{
return challenge;
}
...
...
var binding = new NetTcpBinding(SecurityMode.None);
host = new ServiceHost(typeof(LabListener), new Uri(String.Format("net.tcp://{0}:800/LabListener", Environment.MachineName)));
host.AddServiceEndpoint(typeof(ILabListener), binding, "");
...
LabListenerClient client = new LabListenerClient();
Console.WriteLine(Convert.ToBase64String(client.GetChallenge());
Console.WriteLine(Convert.ToBase64String(client.GetChallenge());
When hosting this service in MS .net on Windows, the output of each GetChallenge is the same and the constructor for LabListener is only called once.
If I host this in mono 2.6.7 under OpenSuSE 11.3, a new LabListener is created for each call to GetChallenge, and two different values are returned.
this is the log output on the server on Linux:
8/26/2010 8:07:57 PM - Starting LabListener session: urn:uuid:5e41d193-c723-4839-abc0-93103dbd63f1, challenge: hDPwoofYUrEjAJ1Q8cWDYw==
8/26/2010 8:07:57 PM - Starting
LabListener session:
urn:uuid:5e41d193-c723-4839-abc0-93103dbd63f1,
challenge: 6/3M4EhiKrAMM2j47MCIpQ==
How do I correct the mono behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您构建 SVN 主干(或现在 - GIT 最新)并重试。
如果不起作用,请写信给 mono/mono-devel 邮件列表并查看答案。
可能是 Mono 错误,维护人员会要求你填写测试或错误
I recommend you to build SVN trunk (or nowadays - GIT latest) and try again.
If doesn't work, write to mono/mono-devel mailing list and see the answer.
Probably it a Mono bug and maintainer will ask you to fill a test or a bug