none
WPF application cannot access WCF websocket service RRS feed

  • Question

  • I'm trying to use a simple WCF service via Websockets (netHttpBinding with transportUsage="Always").

    It works fine when consuming the service from a console application, but throws a timeout error, when consuming it from a WPF application:

    > This request operation sent to
    > http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/
    > did not receive a reply within the configured timeout (00:01:00).

    There is not timeout when switching from transportUsage="Always" to transportUsage="Never".

    Question: How can I access a websocket WCF service from a WPF application?

    Service Contract:

        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            string GetData(int value);
        }


    The Service:

        public class Service1 : IService1
        {
            public string GetData(int value)
            {
                return string.Format("You entered: {0}", value);
            }
        }


    The host's configuration:

        <system.serviceModel>
          <services>
            <service name="WcfServiceLibrary1.Service1">
              <host>
                <baseAddresses>
                  <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
                </baseAddresses>
              </host>
              <endpoint address="" binding="netHttpBinding" contract="WcfServiceLibrary1.IService1" bindingConfiguration="My_NetHttpBindingConfig">
                <identity>
                  <dns value="localhost"/>
                </identity>
              </endpoint>
              <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
          </services>
          <bindings>
            <netHttpBinding>
              <binding name="My_NetHttpBindingConfig">
                <webSocketSettings transportUsage="Always"/>
              </binding>
            </netHttpBinding>
          </bindings>
          <behaviors>
            <serviceBehaviors>
              <behavior>
                <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
                <serviceDebug includeExceptionDetailInFaults="False" />
              </behavior>
            </serviceBehaviors>
          </behaviors>
        </system.serviceModel> 


    Console Code (works fine):

    static void Main(string[] args)
            {
                Service1Client c = new Service1Client("NetHttpBinding_IService1");
                string s = c.GetData(8);
                Console.WriteLine(s);
                Console.ReadLine();
            }


    WPF code (doesn't work):

    private void Button_Click(object sender, RoutedEventArgs e)        
    {            
        Service1Client c = new Service1Client("NetHttpBinding_IService1");            
        string s = c.GetData(5);            
        MessageTextBlock.Text=s;        
    }


    The configuration is identical for both WPF and the console application:

        <system.serviceModel>
            <bindings>
                <netHttpBinding>
                    <binding name="NetHttpBinding_IService1">
                        <webSocketSettings transportUsage="Always" />
                    </binding>
                </netHttpBinding>
            </bindings>
            <client>
                <endpoint address="ws://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
                    binding="netHttpBinding" bindingConfiguration="NetHttpBinding_IService1"
                    contract="ServiceReference1.IService1" name="NetHttpBinding_IService1">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>
    


    Tuesday, September 22, 2015 10:41 AM

Answers

All replies

  • Hi Frank im Wald,

    According to your description, i thought this issue not related with WCF service.  Because your service

    is worked fine. And I test it in console application it worked.

    But I don't  know why it doesn't worked on WPF.

    So, I thought that is wpf issue. Then   I suggest you can  post this case in WPF forum to get better helps.

    Best Regards,

    Grady

    Wednesday, September 23, 2015 6:29 AM
    Moderator
  • Hi Tracymgrady,

    thank you for your hint. I followed your suggestion and posted the question to the WPF forum. But as expected those guys said, this is a WCF issue.

    Are you aware of any working example of using Websockets via netHttpBinding in a WPF application? That would be a great help.

    Best Regards,

    Soeren

    Monday, September 28, 2015 7:37 AM
  • Hi Frank im Wald,

    I test it via WPF application, then it also has a error with timeout.

    But here is a article will explain this issue, please refer.

    1.WPF/WinForm: NetHttpBinding Timeout/Deadlock issue on main UI thread - using web sockets

    I hope that will be helpful to you.

    Best Regards,

    Grady

    • Marked as answer by Frank im Wald Monday, September 28, 2015 8:54 AM
    Monday, September 28, 2015 8:27 AM
    Moderator
  • This explains it. Thanks a lot!
    Monday, September 28, 2015 8:55 AM