my problem....
i am tryingo to access session from Silverlight and WCF basicHttpBinding...
i saw some posts where it's possible (http://www.dotnetspider.com/Silverlight-Tutorial-317.aspx)
Mys cenario is:
Silvelright 4 FW 3.5
in web.config i have
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ViewModelDemo.Web.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ViewModelDemo.Web.Service1Behavior" name="ViewModelDemo.Web.Service1">
<endpoint address="" binding="basicHttpBinding" contract="ViewModelDemo.Web.Service1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
and my service:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Service1
{
[OperationContract]
publicvoid Test()
{
var session = System.Web.HttpContext.Current.Session;
}
}
and it''s call
var client = new Service1Client();
client.GetUserMacroFunctionsCompleted += new System.EventHandler<GetUserMacroFunctionsCompletedEventArgs>(client_GetUserMacroFunctionsCompleted);
client.GetUserMacroFunctionsAsync();
void client_GetUserMacroFunctionsCompleted(object sender, GetUserMacroFunctionsCompletedEventArgs e)
{
var test = ((Collection<Function>)e.Result);
}
HttpContext.Current is always null!
Any suggestions?
Yes HttpContext must be always null because your service configuration doesn't setup ASP.NET compatibility and your service doesn't require ASP.NET compatibility.
Add this to your configuration:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
And change AspNetCompatibilityRequirements
so that your service cannot be hosted without former configuration:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With