Link to home
Start Free TrialLog in
Avatar of pclarke7
pclarke7

asked on

InstanceContextMode.PerSession not working in IIS hosted service

Hello,
I have simple wcf service hosted in IIS 7. The fist call to the service (GetData) creates the Transaction object. I expected that the 2nd call to the service (GetData2) would have the Transaction object available. However the value of MyTrans is null on the 2nd call.   I thought that     [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]  would result in this object being retained for the session. Any idea what I am doing wrong ?

regards
Pat

Service code:
   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
   public class Service1 : IService1
    {
        Transaction MyTrans;
        public Transaction GetData(string value)
        {
            MyTrans = new Transaction();
            MyTrans.companyId="CCS Ltd";
            MyTrans.trans = "Initmenu01";
            MyTrans.userId = "PClarkeirl";
            MyTrans.curSeq = 123;
            return MyTrans;
        }

        public Transaction GetData2(string value)
        {
            MyTrans.nextSeq = MyTrans.nextSeq+1;
            return MyTrans;
        }


Client code:

        {
           
                ServiceReference2.Service1Client client = new ServiceReference2.Service1Client();
                ServiceReference2.Transaction MyClientTrans = client.GetData("XXX");
                MyClientTrans = client.GetData2("XXX");
        }



web.config source
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary7.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary7/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary7.IService1">
          <!--
              Upon deployment, the following identity element should be removed or replaced to reflect the
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information,
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes,
          set the value below to true.  Set to false before deployment
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>
ASKER CERTIFIED SOLUTION
Avatar of pclarke7
pclarke7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pclarke7
pclarke7

ASKER

Sorted this one out myself as there was zero response to the question