Going nuts con questo problema. Ho una soluzione con 2 progetti, uno di questi è un semplice html vecchio con jquery chiamata ajax mentre l'altro è un servizio WCF. La pagina html invierà una chiamata ajax al servizio WCF per ottenere una stringa JSON e usarla a scopo di visualizzazione.Errore WCF: 405 Metodo non consentito
Ora il problema si verifica ogni volta che si esegue in modalità di debug, sia la pagina html che il WCF verranno avviati con una porta diversa. E questo ha creato per me un problema di origine incrociata quando eseguo i test (ad esempio ottenendo un errore 405 Metodo non consentito con il tipo di chiamata = OPZIONI in Firefox). Vorrei triplicare il metodo di chiamata sul mio script ajax e il servizio WCF è lo stesso (GET).
Vorrei cercare su google, ma ho scoperto che devo installare un'estensione o eseguire alcune configurazioni su IIS, che ho trovato ingombrante dal momento che quello che sto facendo è qualcosa di semplice. A seguito di un esempio, mi piacerebbe aggiungere nella seguente configurazione nel mio web.config, ma non ha funzionato:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileService.SimpleMemberInfo" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileService.IMemberInfo" bindingConfiguration="crossDomain" behaviorConfiguration="MobileService.webHttpBehavior">
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
Ognuno ha la minima idea di sbarazzarsi di questo problema fastidioso?
EDIT: solo aggiungere, sto correndo il debug con IIS Express fornito insieme al VS Studio 2012
Aggiungere nel Codice WCF e web.config Aggiornato
[ServiceContract]
public interface IMemberInfo
{
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json
)]
[OperationContract]
string GetMemberInfoById();
// TODO: Add your service operations here
}
Il mio script:
$(document).ready(function() {
$.ajax("http://localhost:32972/SimpleMemberInfo.svc/GetMemberInfoById", {
cache: false,
beforeSend: function (xhr) {
$.mobile.showPageLoadingMsg();
},
complete: function() {
$.mobile.hidePageLoadingMsg();
},
contentType: 'application/json',
dataType: 'json',
type: 'GET',
error: function() {
alert('Something awful happened');
},
success: function (data) {
var s = "";
s += "<li>" + data + "</li>";
$("#myList").html(s);
}
});
});
Questo collegamento potrebbe aiutare http://stackoverflow.com/questions/2202500/wcf-service-405-method-not-allowed-exception – Mihai
Grazie. Ho provato ma non ha funzionato. – ipohfly
ops ok ... ma se nessuna delle risposte ha veramente aiutato allora dovrei scegliere quella più vicina? – ipohfly