WCF客户端:这可能是由于服务端点绑定未使用HTTP协议

时间:2018-09-06 10:22:58

标签: c# .net wcf wcf-binding

我有一个自托管的WCF:

        var localEndPoint = GetLocalEndPoint();
        var host = new WebServiceHost(typeof(Server), new Uri(localEndPoint));
        host.AddServiceEndpoint(typeof(IServer), new WebHttpBinding
        {
            SendTimeout = new TimeSpan(0, 10, 0),
            ReceiveTimeout = new TimeSpan(0, 10, 0),
            OpenTimeout = new TimeSpan(0, 10, 0),
            CloseTimeout = new TimeSpan(0,10,0),
            MaxBufferPoolSize = 2147483647,
            MaxBufferSize = 2147483647,
            MaxReceivedMessageSize = 2147483647,ReaderQuotas = XmlDictionaryReaderQuotas.Max
        }, "");
        var stp = host.Description.Behaviors.Find<ServiceDebugBehavior>();
        stp.HttpHelpPageEnabled = false;
        stp.IncludeExceptionDetailInFaults = true;

        ServiceThrottlingBehavior stb = new ServiceThrottlingBehavior
        {
            MaxConcurrentCalls = Int32.MaxValue,
            MaxConcurrentInstances = Int32.MaxValue,
            MaxConcurrentSessions = Int32.MaxValue
        };
        host.Description.Behaviors.Add(stb);

        ContractDescription cd = host.Description.Endpoints[0].Contract;

        OperationDescription myOperationDescription = cd.Operations.Find("Send");

        DataContractSerializerOperationBehavior serializerBehavior =

            myOperationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();
        if (serializerBehavior == null)
        {
            serializerBehavior =
                new DataContractSerializerOperationBehavior(myOperationDescription)
                {
                    MaxItemsInObjectGraph = 2147483647
                };

            myOperationDescription.Behaviors.Add(serializerBehavior);
        }
        else
        {
            serializerBehavior.MaxItemsInObjectGraph = 2147483647;
        }

        host.Open();

以下是请求WCF服务的代码:

public string GetQuote()
{
 using (ChannelFactory<IServer> cf =
                new ChannelFactory<IServer>(new WebHttpBinding
                {
                    SendTimeout = new TimeSpan(0, 10, 0),
                    ReceiveTimeout = new TimeSpan(0, 10, 0),
                    OpenTimeout = new TimeSpan(0, 10, 0),
                    CloseTimeout = new TimeSpan(0, 10, 0),
                    MaxBufferPoolSize = 2147483647,
                    MaxBufferSize = 2147483647,
                    MaxReceivedMessageSize = 2147483647,
                    ReaderQuotas = XmlDictionaryReaderQuotas.Max
                }, string.Format("http://{0}:{1}", StreamInsightConfiguration.Default.SocketServerHost,
                    StreamInsightConfiguration.Default.SocketPort)))
            {
                cf.Endpoint.Behaviors.Add(new WebHttpBehavior
                {
                    FaultExceptionEnabled = true                        
                });

                foreach (OperationDescription op in cf.Endpoint.Contract.Operations)
                {
                    DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                    if (dataContractBehavior != null)
                    {
                        dataContractBehavior.MaxItemsInObjectGraph = 2147483647;
                    }
                }


                IServer channel = cf.CreateChannel();

                var result = channel.GetQuote(getQuoteRequested);


                return result;
            }
}

向WCF服务发出多个请求时,我有一个例外。

例外是:

在收到对http://192.168.2.101:11000/GetQuote的HTTP响应时发生错误。这可能是由于服务端点绑定未使用HTTP协议。这也可能是由于服务器终止了HTTP请求上下文(可能是由于服务关闭了)。有关更多详细信息,请参见服务器日志。

请注意:我同时发出2000个GetQuote请求。当时我有例外,WCF服务器没有任何例外 所以,您能帮我解决这个问题吗?

0 个答案:

没有答案