WCF服务超时

时间:2018-08-30 02:40:08

标签: asp.net wcfserviceclient

这是我的WCF服务的界面:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    void DoWork();

    [OperationContract]
    void SendData();

    [OperationContract]
    void GetData();

    [OperationContract]
    void GetUpdate();
}

public class StateObject
{
    // Client  socket.  
    public Socket workSocket = null;
    // Size of receive buffer.  
    public const int BufferSize = 20;
    // Receive buffer.  
    public byte[] buffer = new byte[BufferSize];
    // Received data string.  
    public StringBuilder sb = new StringBuilder();
}

.cs文件的代码如下:

public void GetUpdate()
    {
        StartListening();
    }

public static void StartListening()
{
    // Establish the local endpoint for the socket.  
    // The DNS name of the computer  
    IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 1200);

    // Create a TCP/IP socket.  
    Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

    // Bind the socket to the local endpoint and listen for incoming connections.  
    try
    {
        listener.Bind(localEndPoint);
        listener.Listen(200);

        while (true)
        {
            // Set the event to nonsignaled state.  
            allDone.Reset();

            // Start an asynchronous socket to listen for connections.  
            listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);

            // Wait until a connection is made before continuing.  
            allDone.WaitOne();
        }
    }
    catch (Exception e)
    {
    }
}

第一个问题是我收到超时错误。

  

TimeoutException:对“ http://localhost:17263/MyService.svc”的HTTP请求已超过分配的超时时间00:01:00。分配给该操作的时间可能是较长超时的一部分。

第二个错误是

  

WebException:操作已超时

这是我的web.config

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="IncreasedTimeout" sendTimeout="00:05:00" />
            <binding name="BasicHttpBinding_IMyService" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint name="BasicHttpBinding_IMyService" 
            address="http://localhost:17263/MyService.svc"  
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IMyService" 
            contract="MyServiceRef.IMyService" />
    </client>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我在application_start()中呼叫服务

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    MyServiceRef.MyServiceClient myService = new MyServiceRef.MyServiceClient();
    Thread thread = new Thread(() => myService.GetUpdate());
    thread.Start();
    Application["ClientObj"] = myService;
    SqlDependency.Start(constr);
    //trythis.connection.ReceiveData();
}

我没有遇到上面提到的任何问题。因为现在我遇到了有史以来最大的问题-

  

每当我使用WCF运行Web应用程序时,我的VS2015和我的计算机都挂断   服务参考。没有任何回应,只是一切冻结。什么都没有。为什么会这样?

更新: 我搜索了这个问题,它说没有异常捕获,这就是系统冻结的原因。所以我用了try catch块。现在显示了我的网页,但系统也冻结了。响应约为零。我现在能做什么。我读到它发生在tcp连接上,但是如何解决呢?

0 个答案:

没有答案