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(InstanceC ontextMode = InstanceContextMode.PerSes sion)] would result in this object being retained for the session. Any idea what I am doing wrong ?
regards
Pat
Service code:
[ServiceBehavior(InstanceC ontextMode = InstanceContextMode.PerSes sion)]
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.Service1 Client client = new ServiceReference2.Service1 Client();
ServiceReference2.Transact ion MyClientTrans = client.GetData("XXX");
MyClientTrans = client.GetData2("XXX");
}
web.config source
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendl ySynchroni zationCont ext" 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.S ervice1">
<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="WcfServiceLibrar y7.IServic e1">
<!--
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="IMetadataExchang e"/>
</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 includeExceptionDetailInFa ults="Fals e" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
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(InstanceC
regards
Pat
Service code:
[ServiceBehavior(InstanceC
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.Service1
ServiceReference2.Transact
MyClientTrans = client.GetData2("XXX");
}
web.config source
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendl
</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.S
<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"
<!--
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="IMetadataExchang
</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 includeExceptionDetailInFa
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER