2012-08-10 12 views
7

Ajax chiamata:500 System.ServiceModel.ServiceActivationException quando si effettua una chiamata Ajax per il servizio WCF resto

$.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 Interfaccia:

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

Il il servizio è ospitato su IIS6.

Quando chiamo il servizio ricevo il seguente messaggio di errore:

500 System.ServiceModel.ServiceActivationException 

posso chiamare il metodo GetFile e ottenere il flusso di risposta ma ottengo il messaggio di errore quando si chiama GetSearchResults.

Qualsiasi aiuto sarà apprezzato.

+0

Si consiglia di abilitare la traccia (http://msdn.microsoft.com/en-us/library/ms733025.aspx) e di esaminare il log di traccia per il problema esatto quando si tenta di richiamare il metodo GetSearchResults – Rajesh

risposta

9

ho incontrato questo errore per il motivo menzionato di seguito

cancelli memoria Controllare fallirono perché la memoria libera (258187264 bytes) è inferiore al 5% della memoria totale. Di conseguenza, il servizio non sarà disponibile per le richieste in arrivo. Per risolvere questo problema, ridurre il carico sulla macchina o regolare il valore di minFreeMemoryPercentageToActivateService sull'elemento di configurazione serviceHostingEnvironment.

+3

I è stato in grado di confermare che questo era il mio problema cercando errori nel mio registro eventi di Windows (applicazione). Aggiornamento del web.config per impostare minFreeMemoryPercentageToActivateService = "0" ha risolto il problema. – NorthFork

+0

Tuttavia, è necessario avere pieno affidamento (privilegi di amministratore) sul proprio computer per ottenere il funzionamento di minFreeMemoryPercentageToActivateService. –

0

Mille grazie per le vostre risposte e commenti ispirati.

realtà ho incontrato lo stesso errore, ma con diversa storia:

In un primo momento, mi sono "404 (non trovato)" errore del server, che è perché non ho avuto un trasporto per "HTTPS", così come Ne ho già uno per "HTTP".

ho aggiunto un <httpsTransport> al mio elemento <binding>, in modo che si presentava così:

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

Poi ho avuto l'errore 500 System.ServiceModel.ServiceActivationException. Tuttavia, ho navigato in "Visualizzatore eventi> Registro di Windows> Applicazione" e ho riscontrato che "i trasporti non possono essere definiti più di una volta per la stessa associazione". Così, ho deciso di aggiungere un endpoint aggiuntivo con una nuova associazione per il trasporto "HTTPS".

Alla fine, la mia configurazione è simile al seguente:

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

Poi ogni cosa va per il verso giusto e funziona perfettamente.

Nel caso in cui si sviluppa su Visual Studio e utilizzare IIS-Express "Cassini", ricordati di abilitare l'opzione SSL nelle proprietà del sito web del progetto, che racconta IIS Express per preparare un URL di base per l'HTTPS trasporto che hai precedentemente aggiunto al binding.

Problemi correlati