我有一个silverlight项目。同一解决方案中有2个项目。一个是Silverlight,另一个是WCF。在WCF项目中,有一个类,我们在登录时分配所有会话变量。现在,我将一个现有的aspx项目(仅包含login.aspx和home.aspx)添加到同一解决方案中并添加了服务引用。现在aspx项目是启动项目。现在用户将从login.aspx页面而不是login.xaml页面登录。在登录时,我正在设置类中的所有会话变量。从登录页面我将用户重定向到主页。在主页中,用户可以导航到不同的silverlight页面。但是当我在silverlight页面之间导航时,我将所有会话变量都设为null / 0。我怎么解决这个问题?请帮帮我。
这是我的服务web.config文件:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
</appSettings>
<connectionStrings>
<add name="ConnectionString" connectionString="DataSource=Connection\SQLEXPRESS;Initial Catalog=OfficeConnect;UserID=sa;Password=sa" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<hostingEnvironment idleTimeout="10000"/>
<sessionState timeout="60"></sessionState>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportAppServer.Controllers, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportAppServer.DataDefModel, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</assemblies>
</compilation>
<httpRuntime maxRequestLength="2097151" />
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="PictureBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:30:30" receiveTimeout="00:30:30" closeTimeout="00:30:30" openTimeout="00:30:30" >
<readerQuotas
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxDepth="2147483647"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSPictureBinding" maxReceivedMessageSize="2147483647" sendTimeout="00:30:30" receiveTimeout="00:30:30" closeTimeout="00:30:30" openTimeout="00:30:30" >
<readerQuotas
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxDepth="2147483647"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="OfficeConnect.Web.ImageServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="OfficeConnect.Web.ImageServiceBehaviour" name="OfficeConnect.Web.wcfOfficeConnect">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSPictureBinding" contract="OfficeConnect.Web.IwcfOfficeConnect">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
<handlers>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>
</handlers>
<validation validateIntegratedModeConfiguration="false"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"></requestLimits>
</requestFiltering>
</security>
</system.webServer>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="E:\Harsha\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
这是我将服务引用添加到ASP项目时生成的web.config文件
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms" >
<forms defaultUrl="Application_Masters/LoginPage.aspx"
slidingExpiration="true"
name=".ASPXAUTH" timeout="20" cookieless="AutoDetect"
>
</forms>
</authentication>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MashPortalService.MyServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceTimeouts transactionTimeout="05:05:00" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="2147483647" />
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!--<serviceMetadata 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="true" />
<!--<StructureMapServiceBehavior />-->
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:900/mex/"/>
<add baseAddress="net.tcp://localhost:9000/" />
</baseAddresses>
</host>
<endpoint bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
<extensions>
<behaviorExtensions>
</behaviorExtensions>
</extensions>
<bindings>
<basicHttpBinding>
<binding name="LAN_Endpoint1" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
<binding name="BasicHttpBinding_IwcfOfficeConnect" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="LAN_Endpoint1" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
<binding name="WSHttpBinding_IwcfOfficeConnect" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3312/wcfOfficeConnect.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IwcfOfficeConnect"
contract="ServiceReference.IwcfOfficeConnect" name="LAN_Endpoint1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://localhost:3312/wcfOfficeConnect.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IwcfOfficeConnect"
contract="ServiceReference.IwcfOfficeConnect" name="WSHttpBinding_IwcfOfficeConnect">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
这是我在向Silverlight项目添加服务引用时生成的Silverlight客户端配置。
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="LAN_Endpoint1" closeTimeout="00:30:30" openTimeout="00:30:30"
receiveTimeout="00:30:30" sendTimeout="00:30:30" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3312/wcfOfficeConnect.svc"
binding="basicHttpBinding" bindingConfiguration="LAN_Endpoint1"
contract="ServiceReference.IwcfOfficeConnect" name="LAN_Endpoint1" />
</client>
</system.serviceModel>
</configuration>
这是我们维护会话的WCF项目中的类。当我们登录时,我们为所有变量分配会话,并在需要时获取相同的内容。
public class ClsSessionMaintenance
{
public void assign_compdb(int mainlogin)
{
HttpContext.Current.Session["mainloginid"] = mainlogin;
}
public static int getmaindbuserid()
{
int loginId = Convert.ToInt32((string)HttpContext.Current.Session["mainloginid"]);
return loginId;
}
}
配置文件有问题吗?通过WCF服务中的方法,我能够在ClsSessionMaintenance类中成功分配会话。它很好,直到这里。成功登录后,我将用户重定向到HomePage.aspx,该主页具有HomeMaster主页。在HomeMaster页面中,有超链接,以便用户可以导航到不同的Silverlight xaml页面。但是在分配会话之后,我立即调用从ClsSessionMaintenance类获取会话的函数。但我得到会话值为O.为什么会发生?请帮帮我。