2011-06-08 16 views
5

मेरी समस्या ....WCF + सिल्वरलाइट + HttpContext.Current.Session रिक्त है

मैं tryingo सिल्वरलाइट और WCF basicHttpBinding से सत्र तक पहुँचने के लिए कर रहा हूँ ...

मैं कुछ पदों जहां यह संभव है देखा (http://www.dotnetspider.com/Silverlight-Tutorial-317.aspx)

Mys cenario है:

Silvelright 4 परिवार कल्याण 3.5

web.config में मेरे पास है

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

और मेरी सेवा:

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

और यह 'के

   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 फोन हमेशा शून्य है!

कोई सुझाव?

उत्तर

6

हाँ HttpContext हमेशा शून्य होना चाहिए क्योंकि आपकी सेवा कॉन्फ़िगरेशन ASP.NET संगतता सेट नहीं करता है और आपकी सेवा को ASP.NET संगतता की आवश्यकता नहीं होती है।

आपके विन्यास को यह करें:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 

और AspNetCompatibilityRequirements बदल सकते हैं कि आपकी सेवा पूर्व विन्यास के बिना होस्ट नहीं किया जा सकता है:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
0

अद्यतन अपने web.config फ़ाइल शामिल करने के लिए

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

यह काम करना चाहिए, या अन्यथा AspNe भी बदलना चाहिए tCompatibilityRequirements आवश्यक अनुबंध के लिए मोड विशेषता।

1

यह लिंक शायद आपकी मदद करने के लिए।

http://blogs.msdn.com/b/sajay/archive/2006/08/03/687361.aspx

aspNetCompatibilityEnabled="true" मेरी मदद नहीं करता है जब तक मैं ग्राहक बाध्यकारी विन्यास पर allowCookies="true" निर्धारित किया है।