WCF会话ASP.NET托管问题

时间:2012-03-13 17:20:35

标签: asp.net wcf iis

我正在构建一个与现有应用程序对话的WCF服务,并且此应用程序需要访问ASP.NET会话 - 能够查看会话是我无法解决的要求。

我构建了WCF项目 - 并在App.config中进行了以下设置:

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

我还在文件中包含了一个接口和服务实现。在实施之前,我有:

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

这是一个REST服务,所以我的界面开始如下:

// 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();

服务本身托管在另一个Web应用程序中 - 在SearchService.svc文件中,其中包含:

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

我将其添加到托管应用程序的web.config中:

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

我相信我做了所有正确的步骤 - 但是当我尝试运行Web应用程序时,我收到了这个错误:

  

     

System.InvalidOperationException:此服务需要ASP.NET   兼容性,必须在IIS中托管。要么托管服务   在web.config中启用了ASP.NET兼容性的IIS或设置   AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode   属性为Required以外的值。在   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(时间跨度   System.ServiceModel.Channels.CommunicationObject.Open()的超时)   在Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo   信息)“

    <?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <!-- database connection details -->

  </appSettings>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>

    <pages>
      <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/>
      </controls>
    </pages>
  </system.web>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="1048576"/>
      </webServices>
    </scripting>
  </system.web.extensions>
  <location path="Scripts">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="Content">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="jQuery-UI-layout.css">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
      <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_ISearchServiceInterface" 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="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 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://vmwarren27dev.altec-wa.com/Altec.UI.Web.Portal/SearchService.svc/WCPService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISearchServiceInterface" contract="SearchService.ISearchServiceInterface" name="WSHttpBinding_ISearchServiceInterface">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
    </client>
    <services>
      <service name="Altec.UI.Web.SearchService.SearchService">
        <endpoint address="RESTService" binding="webHttpBinding" behaviorConfiguration="json" contract="Altec.UI.Web.SearchService.ISearchServiceInterface">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <endpoint address="WCPService" binding="wsHttpBinding" contract="Altec.UI.Web.SearchService.ISearchServiceInterface">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="json">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="AjaxControlToolkit" publicKeyToken="28f01b0e84b6d53e" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.1.51116.0" newVersion="4.1.51116.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

1 个答案:

答案 0 :(得分:0)

你提到了App.config - 听起来你的服务是一个WCF服务库,你在IIS下托管。如果是这种情况,则需要将WCF配置部分从App.config复制到托管服务的IIS应用程序的Web.config。

库不使用配置文件 - 它们使用调用应用程序的配置文件。