none
How to use pollingDuplex of WCF in ASP.NET RRS feed

  • Question

  • Hi I have a service which is implementing pollingduplex of wcf.I am able to use it in silverlight By giving Binding and Address as it is async call.But I am not able to use it ASP.Net .So can any one help me in consuming it in ASP.net
    Thursday, January 17, 2013 4:58 PM

Answers

  • I think there's already a few issues here if you're trying to create a persistent connection won't work in the 'page' because it'll be destroyed fairly shortly anyway (see page lifecycle http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx).

    Your connection needs to be maintained deeper than the page preferably a background service. Or at the application layer (although iis will recycle when it wants and destroy the connection too).

    Otherwise your svc has no chance to even get a reply back to you before the page is destroyed.

    Also wshttp duplex binding isn't going to like multiple duplex on the same machine (IIS). If the client can't make a connection directly to the svc eg Js and needs to go through your web server. You might consider:- a single connection with callbacks using net.tcp as a background service or application layer with some state/session data used to identify the user, a store of incoming msgs waiting, ajax polling from client browser to iis to collect new msg (could even extend It further using RX.Framework to avoid excessive polling). 

    Hope that helps.


    • Edited by XinTW Saturday, January 19, 2013 3:46 PM
    • Marked as answer by Haixia_XieModerator Thursday, January 24, 2013 10:20 AM
    Saturday, January 19, 2013 3:44 PM

All replies

  • Can you give a little more detail of how you are currently trying to consume the WCF Service from an asp.net application (asp.net is the client?).
    Thursday, January 17, 2013 6:15 PM
  • Hi Sorry for late reply.Below is my UI How I am using my duplexservice.I also used Custome Binding like Silverlight But I am getting an Error like Duplex cant be done by Custome Binding

     public partial class UIChat : System.Web.UI.Page, IServiceCallback
        {
            public EndpointAddress servAddress = null;
            public PollingDuplexHttpBinding binding = null;
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void btnJoin_Click(object sender, EventArgs e)
            {
                servAddress = new EndpointAddress("http://localhost:59849/MyService.svc");
               var binding = new PollingDuplexHttpBinding();
                binding.DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll;
    
                                                            
                 InstanceContext objIC = new InstanceContext(this);
                   ServiceClient obj = new ServiceClient(objIC,binding,servAddress);
                string data= obj.JoinChat(txtJoin.Text);
                lblUser.Text = data;
            }
    
    
            public void ReciveMessage(string message)
            {
                throw new NotImplementedException();
            }
    
            public void UserJoined(string[] users)
            {
                lblUser.Text = users[0].ToString();
            }
    
            public void UserLeft(string[] users)
            {
                throw new NotImplementedException();
            }
        }
    }

    Friday, January 18, 2013 11:46 AM
  • I think there's already a few issues here if you're trying to create a persistent connection won't work in the 'page' because it'll be destroyed fairly shortly anyway (see page lifecycle http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx).

    Your connection needs to be maintained deeper than the page preferably a background service. Or at the application layer (although iis will recycle when it wants and destroy the connection too).

    Otherwise your svc has no chance to even get a reply back to you before the page is destroyed.

    Also wshttp duplex binding isn't going to like multiple duplex on the same machine (IIS). If the client can't make a connection directly to the svc eg Js and needs to go through your web server. You might consider:- a single connection with callbacks using net.tcp as a background service or application layer with some state/session data used to identify the user, a store of incoming msgs waiting, ajax polling from client browser to iis to collect new msg (could even extend It further using RX.Framework to avoid excessive polling). 

    Hope that helps.


    • Edited by XinTW Saturday, January 19, 2013 3:46 PM
    • Marked as answer by Haixia_XieModerator Thursday, January 24, 2013 10:20 AM
    Saturday, January 19, 2013 3:44 PM