我建立這充分說明現有的應用程序的WCF服務,而這個應用程序需要訪問ASP.NET會話 - 看會話的能力是一個要求我無法迴避。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: 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>
右鍵我沒有做到這一點 - 我將修改添加上述全部的web.config。 – 2012-03-13 17:41:24
web.config是否使用服務文件或調用服務的應用程序更新了應用程序的web.config文件? – Tim 2012-03-13 18:12:09
調用該服務的應用程序。 – 2012-03-13 18:14:07