Проблема хостинга ASP.NET в сеансе WCF - PullRequest
0 голосов
/ 13 марта 2012

Я создаю службу WCF, которая обращается к существующему приложению, и этому приложению требуется доступ к сеансам ASP.NET - я не могу обойтись возможностью видеть сеансы.

Я создал WCFproject - и имеют следующий параметр в 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();

Сам сервис размещается в другом веб-приложении - вФайл SearchService.svc, который имеет это:

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

, и я добавил это в web.config хост-приложения:

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

Я считаю, что я сделал все правильные шаги - иТем не менее, когда я пытаюсь запустить веб-приложение, я получаю эту ошибку:

"

System.InvalidOperationException: эта служба требует совместимости с ASP.NET и должна быть размещена в IIS. Любой хостслужба в IIS с ASP.NET-совместимостью включена в web.config или задает для свойства AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode значение, отличное от Required.AspNetCompatibilityRequirementsAttribute.System.ServiceModel.Description.IServiceBehavior.Validate (описание ServiceDescription, serviceHostBase serviceHostBase) в System.ServiceModel.Description.DispatcherBuilder.ValidateDescription (описание сервисного описания, ServiceHostBase serviceHost) сервисный дескриптор ServiceHost для домена.в System.ServiceModel.ServiceHostBase.InitializeRuntime () в System.ServiceModel.ServiceHostBase.OnBeginOpen () в System.ServiceModel.ServiceHostBase.OnOpen (тайм-аут TimeSpan) в System.ServiceModel.ServiceModel.OviceSodeOpenSourceSan.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 голосов
/ 13 марта 2012

Вы упомянули App.config - похоже, ваша служба - это библиотека служб WCF, которую вы размещаете под IIS.В этом случае вам необходимо скопировать раздел конфигурации WCF из файла App.config в файл Web.config приложения IIS, в котором размещается ваша служба.

Библиотеки не используют файлы конфигурации - они используютфайл конфигурации вызывающего приложения.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...