2

Here is the interface for my WCF service:

[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();
}

and the code for .cs file is something like this:

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)
    {
    }
}

The first problem is I'm getting timeout error.

TimeoutException: The HTTP request to 'http://localhost:17263/MyService.svc' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.

2nd error is.

WebException: The operation has timed out

Here is my 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>

I am calling service in 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();
}

I am not getting any issues that I mentioned above. Because Now I am having the Biggest Issue of all time-

My VS2015 and my Computer hangs up whenever I run my web app with WCF Service Reference. There is no response, just everything freezes. Nothing works. Why is this happening?

Update: I searched for the issue and it said that there is no exception catch that's why system freezed. So I used try catch block. Now my web page is shown but then also system freezes. Response is approx zero. What can I do now. I read it happens with tcp connections but how to resolve it?

Usha phulwani
  • 184
  • 4
  • 22
  • on which line its throwing an error? – Prashant Pimpale Aug 30 '18 at 02:44
  • @PrashantPimpale: Editied query.... This is the method which is giving error getUpdate() – Usha phulwani Aug 30 '18 at 02:54
  • the service is running now..Actually I had an extra line of code which was causing issue.. But a new issue is - My VS got hang after 2 minutes. and then it gave timeout error on service. **System.TimeoutException: 'The request channel timed out while waiting for a reply after 00:00:59.9809989. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.'** – Usha phulwani Aug 30 '18 at 03:33
  • I have added sendTimeOut binding But then also it gave time out error. This service gave a lot load on my system. How can reduce that? – Usha phulwani Aug 30 '18 at 03:59
  • Have look at: https://stackoverflow.com/a/1520356/7124761 – Prashant Pimpale Aug 30 '18 at 06:17
  • If anyone sees this question, Please read last 2 lines first. I have edited it with my lastest issue. – Usha phulwani Aug 30 '18 at 11:33

0 Answers0