尝试在我打开的代理/通道内设置一些变量时出现超时异常。我不确定它是坏的 DataContract 还是我没有正确设置的东西。
这是服务接口:
[ServiceContract]
public interface ICommandBoardService
{
[OperationContract]
void Hello();
[OperationContract]
Command_Board.States getState();
[OperationContract]
void setState(Command_Board.States s);
[OperationContract]
string setConnected(int i);
[OperationContract]
int getConnected();
}
这是服务类:
public class CommandBoardService : ICommandBoardService
{
[DataMember]
public Command_Board.States state;
[DataMember]
public int connected = 0;
public void Hello()
{
}
public Command_Board.States getState()
{
return state;
}
public void setState(Command_Board.States s)
{
state = s;
}
public string setConnected(int i){
connected += i;
return "Player "+connected+" Connected";
}
public int getConnected(){
return connected;
}
}
这是我打开主机并调用代理的地方:
ICommandBoardService proxy;
using (ServiceHost host = new ServiceHost(typeof(CommandBoardServiceLibrary.CommandBoardService)))
{
host.AddServiceEndpoint(typeof(
CommandBoardServiceLibrary.ICommandBoardService),
new NetTcpBinding(),
"net.tcp://localHost:9000/CommandBoardEndPoint");
host.Open();
proxy = ChannelFactory<ICommandBoardService>.CreateChannel(
new NetTcpBinding(),
new EndpointAddress(
"net.tcp://localhost:9000/CommandBoardEndPoint"));
proxy.setConnected(0);
proxy.setState(state);
}
当我到达时出现以下错误proxy.setConnected(0)
,即使我将它们翻转过来,我也会遇到同样的错误proxy.setState(state)
这是错误:
This request operation sent to net.tcp://localhost:9000/CommandBoardEndPoint did not receive a reply within the configured timeout (00:01:00). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client.
我能做些什么来修复错误?有人说增加最大缓冲区,但我不知道如何使用 WinForms 来做到这一点。