2012-03-13 3 views
0

Je construis un service WCF qui parle à une application existante, et cette application nécessite l'accès aux sessions ASP.NET - la possibilité de voir des sessions est une exigence que je ne peux pas contourner.Session WCF Hébergement ASP.NET Problème

I construit le projet WCF - et ont le paramètre suivant dans App.config:

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

J'ai aussi inclus une interface et une implémentation du service dans le fichier. Devant la mise en œuvre, j'ai:

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

Ceci est un service REST, donc mon interface commence comme:

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

Le service lui-même est hébergé dans une autre application Web - dans un fichier SearchService.svc qui a ceci:

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

et j'ajouté à la web.config de l'application d'hébergement:

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

je crois que je l'ai fait toutes les bonnes mesures - et pourtant lorsque je tente de lancer l'application web je reçois cette erreur:

"

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

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

Répondre

0

Vous avez mentionné App.config - il semble que votre service est une bibliothèque de services WCF que vous hébergez sous IIS. Si c'est le cas, vous devez copier la section de configuration WCF depuis le fichier App.config vers le fichier Web.config de l'application IIS hébergeant votre service.

Les bibliothèques n'utilisent pas les fichiers de configuration - elles utilisent le fichier de configuration de l'application appelante.

+0

Je l'ai fait - je vais modifier pour ajouter le web.config complet ci-dessus. –

+0

Est-ce que web.config vous avez mis à jour celui de l'application avec le fichier de service, ou l'application qui appelle le service? – Tim

+0

L'application qui appelle le service. –