0

我有一个服务并使用“netstat -anb”验证了当服务运行时,它正在侦听正确的端口(8040)。服务合同包含以下合同:

    [OperationContract]
    bool RegisterPlayer();

服务类本身明确地实现了契约:

    bool IMechService.RegisterPlayer()
    {
        if (P1 != null)
        {
            P1 = OperationContext.Current.GetCallbackChannel<IMechServiceCallback>();
            return true;
        }
        else if (P2 != null)
        {
            P2 = OperationContext.Current.GetCallbackChannel<IMechServiceCallback>();
            return true;
        }
        return false;
    }

svcutil 生成的代理创建以下方法:

public bool RegisterPlayer()
{
    return base.Channel.RegisterPlayer();
}

此代码尝试生成代理并调用该方法。我已经尝试过使用 DuplexChannelFactory 和 svcutil 生成的代理类,并且都给出了相同的结果:

client = new MechServiceClient(new InstanceContext(this));
//client = DuplexChannelFactory<IMechService>.CreateChannel(this, new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8040/MechService"));
client.RegisterPlayer();

Code execution reaches the RegisterPlayer in the proxy class, but proceeds to time out, never running RegisterPlayer on the service. Unfortunately, as it's just timing out, I'm not getting any exceptions or errors to help indicate where to look for issues. So far, I've verified the service is running and appears to be listening on port 8040 using "netstat -anb", and I've established that the mex endpoint is working as intended and publishing metadata. I turned off Windows Firewall. I've also created a separate test project with much simpler implementations to verify I was doing the steps correctly, and the simpler test project works fine. I'm out of ideas for what's causing this to fail, and any advice would be appreciated.

4

2 回答 2

0

Have you tried setting the ConcurrencyMode to ConcurrencyMode.Multiple?

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
class MechServiceImpl : IMechService
{
    // ..
}

The default concurrency mode for a service is ConcurrencyMode.Single, which can cause complications with callbacks.

于 2013-04-07T22:26:41.470 回答
0

Andrew's suggestion to logging helped, basically what fixed it was declaring my OperationContracts to isoneway=true.

于 2013-04-08T19:36:20.487 回答