none
WCF ASP.NET session compatibility hosting problem

    質問

  • I am building a WCF service that speaks to an existing application, and this application requires access to ASP.NET sessions - the ability to see sessions is a requirement I cannot get around.

    I built the WCF project - and have the following setting in App.config:

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

    I also included an interface and an implementation of the service in the file.  In front of the implementation I have:

        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
        [AspNetCompatibilityRequirements(RequirementsMode =
            AspNetCompatibilityRequirementsMode.Required)]
        public class SearchService : ISearchServiceInterface
        {

    This is a REST service, so my interface starts like:

        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface ISearchServiceInterface
        {
    
            [OperationContract]
            [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
            string LoginToWebService_POST(Altec.Framework.Authorization auth);
    
            [OperationContract]
            [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
            string GetTopLevelFolderName_POST();
            


    The service itself is hosted in another web application - in a SearchService.svc file which has this:

    <%@ServiceHost language=c# Debug="true" Service="Altec.UI.Web.SearchService.SearchService" %>

    and I added this to the web.config of the hosting application:

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


    I believe I did all the right steps - and yet when I try to run the web application I get this error:

    "

    System.InvalidOperationException: This service requires ASP.NET compatibility and must be hosted in IIS.  Either host the service in IIS with ASP.NET compatibility turned on in web.config or set the AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode property to a value other than Required.
       at System.ServiceModel.Activation.AspNetEnvironment.ValidateCompatibilityRequirements(AspNetCompatibilityRequirementsMode compatibilityMode)
       at System.ServiceModel.Activation.AspNetCompatibilityRequirementsAttribute.System.ServiceModel.Description.IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
       at System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost)
       at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
       at System.ServiceModel.ServiceHostBase.InitializeRuntime()
       at System.ServiceModel.ServiceHostBase.OnBeginOpen()
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open()
       at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)"

    Any ideas?

    2012年3月13日 17:01

回答

  • It should work. Please check again. Put <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> in web.config (not app.config), and make sure you host the service in IIS.

    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.

    • 回答としてマーク Yi-Lun Luo 2012年3月20日 11:22
    2012年3月15日 5:11

すべての返信

  • What is this service hosted in?  IIS?

    -Dan


    If this answers your question, please Mark as Answer

    2012年3月13日 18:08
  • I wanted it to be hosted in a separate web application - this is my project layout:

    2012年3月13日 18:16
  • Hello, I take your first web application references the second class library project, right? You mentioned you have some setting in App.config. But with your setup, you should put the configuration in the web project's web.config. Anything in class library's app.config is ignored at runtime.

    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.

    2012年3月14日 12:05
  • Right - this: 
      <system.serviceModel>
          <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    Is in the web.config above.  Still not working.
    2012年3月14日 16:53
  • It should work. Please check again. Put <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> in web.config (not app.config), and make sure you host the service in IIS.

    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.

    • 回答としてマーク Yi-Lun Luo 2012年3月20日 11:22
    2012年3月15日 5:11