我有,當我使用GET方法,它工作正常,當我通過將數據與URL一起,但我需要使用POST方法,當沒有數據以POST方法傳遞它工作正常.. 一個WCF REST服務但是當添加一些數據時,它會在IE中返回Bad Request錯誤,並且在Mozilla和Chrome中它只是返回Error.I已經發布了我在wcf服務和ajax方法中使用的代碼below.pls幫助POST方法時,數據在它傳遞不工作?
Ischeduler.cs中的代碼
[ServiceContract]
public interface Ischeduler
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "GetData", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string GetData();
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "GetDataName", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string GetDataName(string Name);
}
scheduler.cs
public string GetData()
{
string getdata = "hgello";
return string.Format("You entered" + getdata);
}
public string GetDataName(string Name)
{
return string.Format("You entered" + Name);
}
在Schedular.aspx 10
Ajax請求按鈕點擊
$("#btnInvoke").click(function() {
$.ajax({
type: "GET",
url: "http://localhost:3125/schedulerAPI_Service/scheduler.svc/GetDataName",
data: '{"Name": "John"}',
dataType: 'json',
processdata: true,
contentType: "application/json; charset=utf-8",
crossdomain: true,
success: function (data) {
alert(data);
},
error: function (xhr, status, error) {
alert("failed " + error);
}
});
WCF Web配置這樣
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<connectionStrings>
<add name="InstaScribeCentralConnectionString" connectionString="Data Source=ATLT53;Initial Catalog=InstaScribeCentral;User ID=sa;Password=bmjobmjo;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="scheduler">
<endpoint address="" behaviorConfiguration="ServiceBehavior" binding="webHttpBinding" contract="Ischeduler"/>
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
</configuration>
當我把jQuery.support.cors = TRUE;在的document.ready,我得到了IE的數據,但同樣的錯誤在Mozilla和Chrome – Deepu 2012-02-04 05:55:40