////这是服务契约
[ServiceContract(Name = "IServices_Contract",SessionMode = SessionMode.Required,CallbackContract=typeof(ICallBackServices))]
public interface IServices
{
[OperationContract]//(IsOneWay = true)]
void Send(string str);
}
public interface ICallBackServices
{
[OperationContract]//(IsOneWay = true)]
void SendCall(string str);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class Services : IServices
{
#region IServices 成员
public void Send(string str)
{
CallBack.SendCall("CallBack : " + str);
}
ICallBackServices CallBack
{
get { return OperationContext.Current.GetCallbackChannel<ICallBackServices>(); }
}
#endregion
}
////////////////////end//////////////////这是客户端private void button1_Click(object sender, EventArgs e)
{
try
{
InstanceContext context = new InstanceContext(new CallBackType());
ServiceReference1.Services_ContractClient client = new ServiceReference1.Services_ContractClient(context);
client.Send("Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
class CallBackType : ServiceReference1.IServices_ContractCallback
{
#region IServices_ContractCallback 成员 public void SendCall(string str)
{
MessageBox.Show(str);
}
#endregion
}以上代码运行报错,如下:发送到 http://jiang-pc/Temporary_Listen_Addresses/dda8f5f4-74dc-4be3-a268-f488a2cf8809/1d3f2ff6-9924-476f-abd2-2317bb5fa132 的请求操作在配置的超时(00:00:57.7238698)内未收到回复。分配给该操作的时间可能是更长超时的一部分。这可能由于服务仍在处理操作或服务无法发送回复消息。请考虑增加操作超时(将通道/代理转换为 IContextChannel 并设置 OperationTimeout 属性)并确保服务能够连接到客户端。
如果我把“服务契约”修改成如下就可以正常运行(客户端访问wcf)[ServiceContract(Name = "IServices_Contract",SessionMode = SessionMode.Required,CallbackContract=typeof(ICallBackServices))]
public interface IServices
{
[OperationContract(IsOneWay = true)]///这里修改成了异步
void Send(string str);
}
public interface ICallBackServices
{
[OperationContract(IsOneWay = true)]///这里修改成了异步
void SendCall(string str);
}我想知道为什么呀? 谢谢给小弟指点一下。
[ServiceContract(Name = "IServices_Contract",SessionMode = SessionMode.Required,CallbackContract=typeof(ICallBackServices))]
public interface IServices
{
[OperationContract]//(IsOneWay = true)]
void Send(string str);
}
public interface ICallBackServices
{
[OperationContract]//(IsOneWay = true)]
void SendCall(string str);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class Services : IServices
{
#region IServices 成员
public void Send(string str)
{
CallBack.SendCall("CallBack : " + str);
}
ICallBackServices CallBack
{
get { return OperationContext.Current.GetCallbackChannel<ICallBackServices>(); }
}
#endregion
}
////////////////////end//////////////////这是客户端private void button1_Click(object sender, EventArgs e)
{
try
{
InstanceContext context = new InstanceContext(new CallBackType());
ServiceReference1.Services_ContractClient client = new ServiceReference1.Services_ContractClient(context);
client.Send("Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
class CallBackType : ServiceReference1.IServices_ContractCallback
{
#region IServices_ContractCallback 成员 public void SendCall(string str)
{
MessageBox.Show(str);
}
#endregion
}以上代码运行报错,如下:发送到 http://jiang-pc/Temporary_Listen_Addresses/dda8f5f4-74dc-4be3-a268-f488a2cf8809/1d3f2ff6-9924-476f-abd2-2317bb5fa132 的请求操作在配置的超时(00:00:57.7238698)内未收到回复。分配给该操作的时间可能是更长超时的一部分。这可能由于服务仍在处理操作或服务无法发送回复消息。请考虑增加操作超时(将通道/代理转换为 IContextChannel 并设置 OperationTimeout 属性)并确保服务能够连接到客户端。
如果我把“服务契约”修改成如下就可以正常运行(客户端访问wcf)[ServiceContract(Name = "IServices_Contract",SessionMode = SessionMode.Required,CallbackContract=typeof(ICallBackServices))]
public interface IServices
{
[OperationContract(IsOneWay = true)]///这里修改成了异步
void Send(string str);
}
public interface ICallBackServices
{
[OperationContract(IsOneWay = true)]///这里修改成了异步
void SendCall(string str);
}我想知道为什么呀? 谢谢给小弟指点一下。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货