none
WCF Test Client Not Working After First Execution RRS feed

  • Question

  • I have successfully hosted a WCF inside a Windows Service. The WCF in turn interacts with a oData service. I'm able to call the service via a Test Client from both my local & network computer. The service behaves such that when I execute my Test Client, an entry is created/updated/deleted in a table on the SAP end (oData service). However, the problem is after I execute the Test Client for the very first time after installing & starting the Windows Service, to create an entry (say), it runs perfectly without any error and the entry gets created (checked on SAP end), but thereafter, when I run the Test Client again, it throws a System.TimeoutException:

    "This request operation sent to net.tcp://16.181.241.173:8777/Service1 did not receive a reply within the configured timeout (00:01:00). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client."

    I have tried out all possible solutions suggested by various people on various forums. I am however, unable to understand why and how the Test Client runs for once and not thereafter, unless I restart the service. Atleast, the connection is getting created, as I can understand. Also, I have closed the host and thread on the OnStop() event of the service.

    Kindly help me with the problem. Any suggestions are welcome. Thank you.

    • Changed type Sreyan Choudhury Tuesday, May 21, 2013 11:16 AM Wrongfully marked type as 'Discussion'
    Tuesday, May 21, 2013 11:03 AM

Answers

All replies

  • Are you using singleton WCF service object? InstanceContextMode attribute?


    ViBi

    Tuesday, May 21, 2013 11:28 AM
  • No ViBi, I don't think so. No where have I instantiated any Singleton Class and haven't use anything like 'InstanceContextMode'. Should I share anything (code/config/etc.) that may relate to the problem? Thank you.
    Tuesday, May 21, 2013 11:41 AM
  • Hi, Does it work as your expected for a reality client?

    What do you mean with "run the Test Client again"? Is it mean start a new call?

    I make a test on my side with no issue, I use this sample

    http://msdn.microsoft.com/en-us/library/ms733069.aspx

    Wednesday, May 22, 2013 3:24 AM
  • Hi Nico,
    Yes, it does work for a reality client but only for the first instance. If I try running the client program again, it throws the exception. By "run the Test Client again", I meant F5 (start debugging) on the Client program again. I hope that is a new call, as you meant?

    I used : "How to: Host WCF in a Windows Service Using TCP"  (Sorry, its not allowing me to post links yet :[ . Kindly google it to see the msdn link) to develop my project along with a few changes that I made to the app.config files to make it discoverable over the network.

    Thank you for answering. It would be kind if you could help me out, further. :]


    Wednesday, May 22, 2013 3:55 AM
  • The reality client still runs for once. The WCF Test Client threw an exception as below:

    "This request operation sent to net.tcp://localhost:8777/Service1 did not receive a reply within the configured timeout (00:01:00).  The time allotted to this operation may have been a portion of a longer timeout.  This may be because the service is still processing the operation or because the service was unable to send a reply message.  Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client.

    Server stack trace:
       at System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at IService1.Create(String street, String bank_ctry, String bank_name, String bank_key, String region, String city)
       at Service1Client.Create(String street, String bank_ctry, String bank_name, String bank_key, String region, String city)"

    My Test client config is as follows:

    <configuration>
        <system.serviceModel>
            <bindings>
                <netTcpBinding>
                    <binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                        hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                        maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                        maxReceivedMessageSize="65536">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="None">
                            <transport clientCredentialType="None" protectionLevel="None" />
                            <message clientCredentialType="None" />
                        </security>
                    </binding>
                </netTcpBinding>
            </bindings>
            <client>
                <endpoint address="net.tcp://localhost:8777/Service1" binding="netTcpBinding"
                    bindingConfiguration="NetTcpBinding_IService1" contract="IService1"
                    name="NetTcpBinding_IService1">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>
    </configuration>


    Wednesday, May 22, 2013 4:54 AM
  • Can you please post the client side code (test client I mean)....I hope you are creating the proxy object in some global scope and not disposing the object in your button click call.

    If you are doing that then when you run your test application the proxy object will be created in say constructor or somewhere in the global scope whereas you will make the call to the service in the button click and dispose the proxy object in the button click. Then next time if you click the button, since the proxy object is already disposed hence your second call will throw exception.


    ViBi

    Wednesday, May 22, 2013 5:25 AM
  • Here's the Client side code ViBi:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    
    namespace WcfServiceLibrary2Consume
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("TEST CREATION!");
                var testClient = new ServiceReference1.Service1Client();
               
               try
               {
                   testClient.Create("s35", "IN", "RBI", "90003993", "12", "MOHALI");
                   testClient.Close();
               }
               catch (Exception ex)
               {
                   Console.WriteLine(ex.ToString());
                   Console.Read();
               }
            }
            
        }
    }
    

    Client App.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <netTcpBinding>
                    <binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                        hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                        maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
                        maxReceivedMessageSize="2147483647">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="None">
                          <!--  <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                            <message clientCredentialType="Windows" /> -->
                        </security>
                    </binding>
                </netTcpBinding>
            </bindings>
            <client>
                <endpoint address="net.tcp://16.181.241.173:8777/Service1" binding="netTcpBinding"
                    bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
                    name="NetTcpBinding_IService1">
                 <!--   <identity>
                        <dns value="localhost" />
                    </identity>   -->
                </endpoint>
            </client>
        </system.serviceModel>
    </configuration>

    Thank you.

    Wednesday, May 22, 2013 5:33 AM
  • Client side code is okay. Wanted to know, when you make the call 2nd time, are you getting the exception inside your Create() function in server side or it is simply giving exception in the client side code?

    And what Close() function do?


    ViBi


    • Edited by vkbishnoi Wednesday, May 22, 2013 5:45 AM
    Wednesday, May 22, 2013 5:43 AM
  • It is a Client side exception, ViBi. The Close() causes the object to transition from its current state to closed state. Thank you.
    Wednesday, May 22, 2013 6:02 AM
  • Can you post your sequence of operations in server side? I mean the actual steps happening like Create() function inside do what....whether it uses threads...calls another service...etc..

    You can check this also

    http://stackoverflow.com/questions/9204510/wcf-service-only-works-for-the-first-call


    ViBi

    Wednesday, May 22, 2013 8:01 AM
  • Hi ViBi,

    I checked out your link. Thank you. However, I haven't used threads to start or host the service.

    The operations that run on server side are:

    • WCF service calls an oData service
    • Windows Service hosts the WCF
    • Service exposed to other computers on network via tcp/ip

    I'm sorry, I couldn't post the service code due to inclusion of confidential information. :[

    What options do I need to check or ensure to avoid any kind of conflict? Kindly guide.

    Thank you.

    Wednesday, May 22, 2013 9:20 AM
  • Can you just comment out the call to your OData service and then see if the exception is coming or not in the 2nd call? Is your OData Service call take lot of time to complete?

    It will be better to increase all the timeout values to some safe number (at both server as well as client)

    closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

    I think make all of them to 10 minutes.


    ViBi


    • Edited by vkbishnoi Wednesday, May 22, 2013 9:50 AM
    Wednesday, May 22, 2013 9:49 AM
  • Hi ViBi,

    I have been trying out exactly what you said, before even reading your post. I came across a weird behavior though!!

    I commented out everything in the oData service and just added a message (when the control would return back to the client) -- "Service Responding!". It gave me "Service Responding" message on every call I made from the client. Now, I un-commented the service code and tried running. The problem would be the same, running for the first time and then timeout exception on successive calls. So, I increased all timeouts to 10:00 as you suggested. I still kept the "Service Responding!" message to understand where the exception was actually being thrown. Surprisingly, the call is getting returned to the client without any exception at all, each time, but is not performing the expected tasks. It performs the expected the task only for the first time, here too.

    I think the problem lies in the oData service call itself or on the WCF end, but can't really figure out what is to be done! :( Any suggestions?

    Thank you.

    Wednesday, May 22, 2013 10:42 AM
  • It seems, your OData service is not returning the control back to your WCF service. It is hanging your WCF service.

    Try this

    1. Call came to your WCF service Create() method

    2. Inside create method, launch a thread and inside this thread make a call to your OData service.

    3. Now again call the Create() method from Client and see whether it works 2nd time or not.


    ViBi

    Wednesday, May 22, 2013 11:20 AM
  • I don't know how to do that. I'm rather confused. There is no Create() or any such methods inside the WCF Service class. The code for the oData service is directly written inside 

    public class Service1 : IService1

    :( I don't know how I can implement a thread here. Sorry for being a moron! :(

    Thank you.

    Wednesday, May 22, 2013 11:43 AM
  • Sir, What are you saying...Yours is a WCF OData (i.e. WCF Data Service) and it is based on netTcpBinding??

    Check this out

    http://stackoverflow.com/questions/3639068/can-you-use-wcf-data-services-ne-odata-ne-astoria-ne-ado-net-data-service-wi

    IN your error log

    This request operation sent to net.tcp://16.181.241.173:8777/Service1 did not receive a reply within the configured timeout (00:01:00).

    seems you are using a netTcp based endpoint for OData. I am not sure whether that is possible or not.


    ViBi

    Wednesday, May 22, 2013 1:00 PM
  • Hi ViBi,

    I think I get what you're trying to say. I went through the article and explored additional options. For now, my question has been answered! :) Thanks a lot.

    Cheers.

    Thursday, May 23, 2013 3:37 AM