J'essaie d'appeler une méthode auto-hébergée wcf de jquery mais, je reçois toujours le message: "méthode non autorisée". J'ai trouvé quelques réponses à ce problème sur ce forum mais rien n'a fonctionné pour moi .... ps. Cela fonctionne très bien lorsque j'ajoute la référence sur une application de console et la consomme.wcf self hosting jquery
c'est une forme de fenêtres forme auto-hébergé app
charge:
ServiceHost host = new ServiceHost(typeof(MyServices), new Uri[] { });
host.Open();
App.Config
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceConfig" name="MyServices">
<endpoint address="srv" binding="basicHttpBinding" contract="Operations" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8766" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceConfig">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
contrat d'exploitation:
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string Test();
Service:
public string Test()
{
return "Good!";
}
JQuery
$.ajax({
url: "http://localhost:8766/Test",
contentType: "application/json",
processData: false,
//data: '{}', // tried passing data
type: "GET", // tried POST and pass nothing(deleting this param), but nothing...
success: function (msg) {
console.log(msg);
}
});