Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question 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:

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

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

500 System.ServiceModel.ServiceActivationException

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

Any help will be appreciated.

I would suggest you to enable tracing (msdn.microsoft.com/en-us/library/ms733025.aspx) and inspect the trace log for the exact problem when trying to invoke the GetSearchResults method – Rajesh Jul 10, 2013 at 14:50

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.

I was able to confirm this was my problem by searching for errors in my Windows Event Log (Application). Updating the web.config to set minFreeMemoryPercentageToActivateService="0" did fix the issue. – NorthFork May 29, 2014 at 16:32 However you do need full trust (Administrator Privileges) on your machine to get minFreeMemoryPercentageToActivateService work.. – Fahad Abid Janjua Sep 26, 2014 at 5:49

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

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

<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.ServiceActivationException error. 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.

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.

Add site bindingGo to the IIS => then Default Website=> right Click on that => Edit Bindings=> click on ADD Button=> add HTTPS bindings there

Details ARE in shown screenshot

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.