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

时间:2012-08-10 10:33:32

标签: ajax wcf

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接口:

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

该服务托管在IIS6上。

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

500 System.ServiceModel.ServiceActivationException

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

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:13)

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

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

答案 1 :(得分:1)

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

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

起初,我收到了“404(Not Found)”服务器错误,这是因为我没有“HTTPS”的传输,而且我已经有一个用于“HTTP”。

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

然后我收到500 System.ServiceModel.ServiceActivationException错误。但是,我导航了“事件查看器&gt; Windows日志&gt;应用程序”,发现“传输不能超过同一绑定的时间”。因此,我决定为“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>

然后每件事情都以正确的方式完美运作。

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

答案 2 :(得分:1)

Add site binding转到 IIS => 然后默认网站 => 右键单击​​那个 => 编辑绑定 => 单击添加按钮 => 在那里添加 HTTPS 绑定

详情见截图