我想從jquery調用wcf自我託管的方法,但是,我總是得到消息:「方法不允許」。我發現這個論壇上的這個問題的一些答案,但沒有對我工作.... PS。當我在控制檯應用程序中添加引用並使用它時,它工作正常。wcf自我託管jquery
它是一個窗口形成自託管應用程序
形式負載:
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>
經營合同:
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string Test();
服務:
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);
}
});