Click here to Skip to main content
13,596,190 members
Rate this:
Please Sign up or sign in to vote.
See more:
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
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();

<?xml version="1.0"?>

  For more information on how to configure your ASP.NET application, please visit

    <compilation debug="true" targetFramework="4.0" />

        <add name="pollingDuplexHttpBinding"

                              type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex, Version=,Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <service name="WebChatService.MyService" behaviorConfiguration="ServBehave">



        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
        <behavior name="ServBehave">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />

    <serviceHostingEnvironment aspNetCompatibilityEnabled="false"



Interface Part
using System.Collections.Generic;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace WebChatService
    /// <summary>
    /// Service Interface: Holds signature of methods in service
    /// which are hosted for others to use them.
    /// </summary>
    [ServiceContract(CallbackContract = typeof(IServiceCallback))]
    public interface IService

        string JoinChat(string emailId);

        [OperationContract(IsOneWay = true)]
        void LeaveChat(string emailId);

        [OperationContract(IsOneWay = true)]
        void RemoveUserFromChat(string emailId);


    /// <summary>
    /// Callback Interface: Holds methods which are needed by service 
    /// to call the UI back in case of any event is held in service.
    /// </summary>
    public interface IServiceCallback
        [OperationContract(IsOneWay = true)]
        void ReciveMessage(string message);

        [OperationContract(IsOneWay = true)]
        void UserJoined(IEnumerable<string> users);

        [OperationContract(IsOneWay = true)]
        void UserLeft(IEnumerable<string> users);
Posted 22-Jan-13 20:20pm
Updated 22-Jan-13 20:21pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180621.3 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100