WCF+ duplex + Windows Form Application (ButtonClick) Trouble RRS feed

  • General discussion

  • Hi,

    I have WCF classes and now project to do. My teacher is not smart and gave as to write app with streaming and duplex (I know that is impossible, but I found backdoor from this situation - I'm sending pics under 60KB).

    My code worked well so far as I start wrote my GUI in Windows Form Application. 

    When I'm testing it via console - everything work well. But, when I want to use buttons in my GUI i have this exception:

    An unhandled exception of type 'System.TimeoutException' occurred in mscorlib.dll
    Additional information: This request operation sent to net.tcp://localhost:7756/Przesylanie did not receive a reply within the configured timeout (00:00:59.9740007).  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.

    Here bunch of code:


    public void WyslijstrumienNaSerwer()
                IPrzesylanieCallback callback = OperationContext.Current.GetCallbackChannel<IPrzesylanieCallback>();
                string sciezka = @"E:\5 semestr\Fras\Se płotek\Lab6\WcfServiceContractZadanie2\Host\bin\Pliki\" + "plik_odebrany.jpg";
                string filePath = Path.Combine(System.Environment.SystemDirectory, sciezka);


    namespace WcfServiceContractZadanie2
        [ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IPrzesylanieCallback))]
        public interface IPrzesylanie
            void WyslijstrumienNaSerwer();
        public interface IPrzesylanieCallback
            [OperationContract(IsOneWay = true)]
            void WyslijStrumien(string filePath);

    Client + callback:

    namespace Aplikacja
        static class Program
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            static void Main()
                PrzesylanieClient klient = new PrzesylanieClient(new InstanceContext(new PrzesylanieCallback()), "NetTcpBinding_IPrzesylanie");
                Application.Run(new Form1());
        public class PrzesylanieCallback : Referencja1.IPrzesylanieCallback
            public void WyslijStrumien(string filePath)
                Form1 o1 = new Form1();
                //  Pobieranie obrazka od klienta
                string sciezka = @"E:\5 semestr\Fras\Se płotek\Lab6\WcfServiceContractZadanie2\Aplikacja\bin\Pliki\" + o1.wybrany();
                string filePathZrodla = Path.Combine(System.Environment.SystemDirectory, sciezka);
                //Otwieranie obrazka
                Stream strumien = null;
                    FileStream imageFile = File.OpenRead(filePathZrodla);
                    strumien = (Stream)imageFile;
                catch(IOException ioe)
                    Console.WriteLine("Wyjatek otwierania pliku: {0}", ioe.ToString());
                    throw ioe;
                //  Zapisywanie obrazka
                o1.SaveFile(strumien, filePath);

    I wrote methods 'SaveFile' which works correctly.

    As you see, I'm testing my code in the begining of Main function in Clinet and that works well.

    But when I'm using the same code in Forms:

            private void btnPrzeslijPlikNaSerwer_Click(object sender, EventArgs e)
                   PrzesylanieClient klient = new PrzesylanieClient(new InstanceContext(new PrzesylanieCallback()), "NetTcpBinding_IPrzesylanie");

    it does not work. Compiler is returnig me to References.cs here:

    public void WyslijstrumienNaSerwer() {
    and gives me exception I mentioned earlier.

    Waiting for any respone!

    Tuesday, December 29, 2015 12:14 AM

All replies


    The service is taking more than 1:00 minute, and the client sets the timeout that it will timeout on if the service doesn't  respond back in the timeframe.

    On the other hand, the service could be sending something back to the client that may take too long and timeout.

    The settings on both sides are adjustable.  

    Tuesday, December 29, 2015 1:16 AM
  • Thanks for respond.

    But in my opinion the problem is not in the timeout options. My code works well via Console Application and I have no problem with respond with server-client connection.

    It appears when I want to use Windows Forms and I don't know why...

    Tuesday, December 29, 2015 10:18 AM