Click here to Skip to main content
15,921,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hello,
 I have simple wcf service hosted in IIS 7. The first 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>
Posted
Updated 14-Mar-15 2:55am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900