2011-06-08 12 views
5

mi problema ....WCF Silverlight + + HttpContext.Current.Session es nulo

soy tryingo para acceder a la sesión de Silverlight y WCF basicHttpBinding ...

vi algunos puestos en los que es posible (http://www.dotnetspider.com/Silverlight-Tutorial-317.aspx)

Mys Cenario es:

Silvelright 4 FW 3,5

en web.config tengo

<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> 

y mi servicio:

[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
[ServiceBehavior(IncludeExceptionDetailInFaults = true)] 
public class Service1 
{ 
    [OperationContract] 
    publicvoid Test() 
    { 
     var session = System.Web.HttpContext.Current.Session; 
    } 
} 

y es de llamar

   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 siempre es nulo!

¿Alguna sugerencia?

Respuesta

6

Sí HttpContext debe ser siempre nulo porque la configuración de su servicio no configura la compatibilidad ASP.NET y su servicio no requiere compatibilidad con ASP.NET.

Agregue esto a su configuración:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 

Y cambiar AspNetCompatibilityRequirements para que su servicio no se puede recibir sin configuración anterior:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
0

Actualizar archivo de su web.config para incluir

<system.serviceModel> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />  
</system.serviceModel> 

Esto debería funcionar, o también cambiar el AspNe tCompatibilityRequirementsMode atributo en el contrato requerido.

Cuestiones relacionadas