2
我正在通過WCF Web服務將Web表單連接到SSIS。我的問題始於作爲交叉引用服務的問題,現在它已成爲服務提供錯誤的問題,如標題中所示。WCF AJAX無法推斷模式。請求/響應正文包裝
這裏是我的代碼:
//Service
[ServiceContract]
public interface IExtractionService
{
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/SubmitExtraction")]
string runExtraction(string start, string end, string packageName);
}
public string runExtraction(string start, string end, string packageName)
{
//code to run SSIS package
}
//Javascript
$("#btnSubmit").click(function() {
var startDateTime = ($("#from").data + " 00:00:00");
var endDateTime = ($("#to").data + " 23:59:59");
var ExtractionData = {
"start": startDateTime,
"end": endDateTime,
"packageName": $("#packageName").data
};
$.ajax({
type: "POST",
url: "ExtractionService.svc/runExtraction",
data: JSON.stringify(ExtractionData),
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function (data, status) {
alert("success..." + data);
},
error: function() {
alert("Failed");
}
})
})
//Global.asax.cs
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if(HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
//web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IExtractionService" />
</basicHttpBinding>
</bindings>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
<client>
<endpoint address="http://localhost:49313/ExtractionService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IExtractionService"
contract="ExtractionServices.IExtractionService" name="BasicHttpBinding_IExtractionService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
這應該是你所需要的。如果還有其他的東西,我可以把它說出來。我覺得它很小。我一直在把所有這些都放在一起,我知道它可能看起來很波濤洶涌,但我覺得它的大部分都處於工作狀態。任何幫助表示讚賞。
修復了我自己的問題。編輯以顯示出錯的地方。 – Ken
如果您修復了它,您應該創建一個解釋您所做的事情的答案,而不是編輯您的問題。這對於其他可能與您具有相同問題的人來說更清楚。我已經回滾你編輯(不要擔心,你仍然可以從編輯歷史http://stackoverflow.com/posts/31122001/revisions中檢索它)。 –
在下面添加了一個答案,解決了我的問題。 – Ken