ebcrypto
ebcrypto

Reputation: 610

SilverLight Enabled Wcf Service - can't keep track of session

I'm new to Silverlight and WCF services. I'm trying to write a client application that can manipulate an object server side.

My problem is that each time my Silverlight client makes a call to the service, it enters into the constructor systematically

public SilverLightEnabledWcfService()
        {
        }

In the below example, I simply want to increment or decrement a number depending on the activity client side.

How am I supposed to do this properly?

I also tried to create a regular ASP.net client page and I got the same result, ie the server doesn't remember the session. So I don't think the problem is in my client, but I'm still happy to post the code if it helps.

Thanks !!

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Count.Library;

namespace Count.WebApp
{
    [ServiceContract(Namespace = "")]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class SilverLightEnabledWcfService
    {
        public SilverLightEnabledWcfService()
        {
        }

        private Class1 _class1;

        [OperationContract]
        public int Add1()
        {
            if (_class1 == null)
                _class1 = new Class1(0);
            _class1.Add1();
            return Value;
         }

        [OperationContract]
        public int Remove1()
        {
            if (_class1 == null)
                _class1 = new Class1(0);
            _class1.Remove1();
            return Value;
         }

        public int Value
        {
            get
            {
                return _class1.Count;
            }
        } 
    }
}

Upvotes: 2

Views: 528

Answers (1)

Ozan
Ozan

Reputation: 4415

Sessions require the wsHttpBinding, but this is not supported by Silverlight. There are workarounds, though:

http://web-snippets.blogspot.com/2008_08_01_archive.html

http://forums.silverlight.net/forums/t/14130.aspx

Upvotes: 1

Related Questions