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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11899881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 10:48:34  来源:igfitidea点击:

500 System.ServiceModel.ServiceActivationException when making an Ajax call to WCF rest service

ajaxwcf

提问by user1589967

Ajax Call:

阿贾克斯调用:

   $.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);
        }
    })

WCF Interface:

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

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>

The service is hosted on IIS6.

该服务托管在 IIS6 上。

When I call the service I get the following error message:

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

500 System.ServiceModel.ServiceActivationException

I can call the GetFilemethod and get the response stream but I get the error message when calling GetSearchResults.

我可以调用该GetFile方法并获取响应流,但是在调用GetSearchResults.

Any help will be appreciated.

任何帮助将不胜感激。

回答by Fahad Abid Janjua

I encountered this error for the reason mentioned below

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

Memory gates checking failed because the free memory (258187264 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

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

回答by Wael AlGhool

Many thanks for your inspired replies and comments.

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

I actually encountered the same error but with different story:

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

At first, I got "404 (Not Found)" server error, which is because I did not have a transport for "HTTPS" as well as I already have one for the "HTTP".

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

I added a <httpsTransport>to my <binding>element, so it looked like this:

<httpsTransport>在我的<binding>元素中添加了一个,所以它看起来像这样:

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

Then I got the 500 System.ServiceModel.ServiceActivationExceptionerror. However, I navigated "Event Viewer > Windows Log > Application" and found that "transports cannot be defined more than a time for the same binding". So, I decided to add an additional endpoint with a new binding for the "HTTPS" transport.

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

At the end, my configuration looks like the following:

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

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

Then every things goes the right way and works perfectly.

然后每件事都以正确的方式进行并且完美地工作。

In case you develop on visual Studio and use IIS-Express "Cassini", remember to enable SSL option in the properties of the website-project, that tells IIS-Express to prepare a base URL for the HTTPS transport that you previously added to binding.

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