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?