在对WCF休息服务进行Ajax调用时出现500 System.ServiceModel.ServiceActivationException

use*_*967 11 ajax wcf

Ajax调用:

   $.ajax({
        type: "POST",
        url: "http://SomeService/ServiceName.svc/GetSearchResults",
        data: JSON.stringify({ parameters: serviceParameters }),
        contentType: "application/json; charset=utf-8",
        dataType: "XML",
        success: function (response) {
            $("#xmlText").text(response.xml);
        },
        error: function (msg) {
            alert(msg.toString);
        }
    })
Run Code Online (Sandbox Code Playgroud)

WCF接口:

[OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Json,
                    UriTemplate = "GetSearchResults")]
        XElement GetSearchResults(inputParameters parameters);

        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "getFile")]
        Stream GetFile(DocInfo info);
Run Code Online (Sandbox Code Playgroud)

Web.config文件:

 <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <customErrors mode="Off"/>
  </system.web>

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

 <system.serviceModel>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
   </serviceHostingEnvironment>
   <standardEndpoints>
     <webHttpEndpoint>
       <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
     </webHttpEndpoint>
   </standardEndpoints>
 </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

该服务托管在IIS6上.

当我调用该服务时,我收到以下错误消息:

500 System.ServiceModel.ServiceActivationException
Run Code Online (Sandbox Code Playgroud)

我可以调用该GetFile方法并获取响应流但是在调用时我收到错误消息GetSearchResults.

任何帮助将不胜感激.

Fah*_*jua 13

我出于下面提到的原因遇到了这个错误

内存门检查失败,因为可用内存(258187264字节)小于总内存的5%.因此,该服务将无法用于传入请求.要解决此问题,请减少计算机上的负载或调整serviceHostingEnvironment配置元素上的minFreeMemoryPercentageToActivateService的值.

  • 我通过在Windows事件日志(应用程序)中搜索错误来确认这是我的问题.更新web.config以设置minFreeMemoryPercentageToActivateService ="0"确实解决了问题. (3认同)

Wae*_*ool 9

非常感谢您的启发性回复和评论。

我实际上遇到了同样的错误,但故事不同:

一开始,我收到“404(未找到)”服务器错误,这是因为我没有“HTTPS”的传输,而我已经有“HTTP”的传输。

<httpsTransport><binding>元素中添加了 a ,所以它看起来像这样:

<bindings>
  <customBinding>
    <binding name="CustomBinding_ITheService">
      <httpTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
      <httpsTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
    </binding>
  </customBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

然后我得到了500 System.ServiceModel.ServiceActivationException错误。但是,我导航“事件查看器 > Windows 日志 > 应用程序”,发现“不能为同一绑定定义多次传输”。因此,我决定为“HTTPS”传输添加一个带有新绑定的附加端点。

最后,我的配置如下所示:

<services>
  <service name="TheService" behaviorConfiguration="WebHttpBehavior_ITheService">
    <endpoint binding="customBinding" bindingConfiguration="CustomBinding_ITheService" contract="ITheService" behaviorConfiguration="EndPointBehavior_ITheService" />
    <endpoint binding="customBinding" bindingConfiguration="CustomBinding_ITheService_Secured" contract="ITheService" behaviorConfiguration="EndPointBehavior_ITheService" />
  </service>
</services>

<bindings>
  <customBinding>
    <binding name="CustomBinding_ITheService">
      <httpTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
    </binding>
    <binding name="CustomBinding_ITheService_Secured">
      <httpsTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
    </binding>
  </customBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

然后一切都会按照正确的方式进行并且完美地进行。

如果您在 Visual Studio 上进行开发并使用 IIS-Express“ Cassini ”,请记住在网站项目的属性中启用 SSL 选项,该选项告诉 IIS-Express 为您之前添加到绑定的 HTTPS 传输准备基本 URL 。