I'm trying to call an wcf self hosted method from jquery but, i'm aways getting the message: "method not allowed". I found some answers to this issue on this forum but nothing worked to me.... ps. It works fine when I add the reference on a console app and consume it.
it's an windows forms self-hosted app
form load:
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>
Operation Contract:
[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);
}
});