WCF操作超时异常

时间:2017-11-15 14:14:22

标签: c# wcf

当我尝试调用Test WCF方法时,我得到OperationTimeOut异常。 当我将Test方法的IsOneWay设置为true时,它可以正常工作,但是当我删除它时 我发现异常。没有Debug程序可以正常工作

服务

public class SyncService : ISyncContract
{
    STOREDBEntities db = STOREDBEntitiesSingleTon.Instance;
    public virtual void Test()
    {
        Debug.WriteLine("Test");
    }

}

和合同

public interface ISyncContract
    {
        [OperationContract(IsOnWay=false)]
        void Test();
    }

服务器代码

void StartServer()
    {
        Uri address = new Uri($"http://{Ip}:{Port}/Sync");

        BasicHttpBinding binding = new BasicHttpBinding();

        binding.MaxReceivedMessageSize = int.MaxValue;

        Type contract = typeof(ISyncContract);

        host = new ServiceHost(service);

        host.AddServiceEndpoint(contract, binding, address);

        try
        {
            host.Open();
            Log += $"Server Started At {DateTime.Now}";
        }
        catch (Exception ex)
        {
            Log = ex.Message;
        }
    }

客户代码

 void ConnectToServer()
    {
        Uri address = new Uri($"http://{Ip}:{port}/Sync");
        BasicHttpBinding binding = new BasicHttpBinding();
        EndpointAddress endpoint = new EndpointAddress(address);

        ChannelFactory<ISyncContract> factory = new ChannelFactory<ISyncContract>(binding, endpoint);
        try
        {
            channel = factory.CreateChannel();
            channel.Test();
            IsConnectedWithServer = true;
            MessageBox.Show("Successfully Connected!");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

fiddler中的屏幕截图 enter image description here

有人可以解释为什么我会遇到异常以及如何为返回值

的方法解决它

0 个答案:

没有答案