我正在努力通过WCF Web服务将Web表单连接到SSIS。我的问题始于交叉引用服务的问题,现在它已成为服务中出现错误的问题。
这是我的代码:
//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>
这应该是你所需要的。如果还有别的,我可以说出来。我觉得它很小。我一点一点地把所有这些放在一起,我知道它看起来很不稳定,但我觉得它的大部分都处于正常工作状态。任何帮助表示赞赏。
答案 0 :(得分:2)
在我访问url的ajax调用中,我按如下方式输入方法名称:
$.ajax({
type: "POST",
url: "ExtractionService.svc/runExtraction",
data: JSON.stringify(ExtractionData),
contentType: "application/json; charset=utf-8",
dataType: "json",
该服务指定了一个uri,直到第二眼之后才点击我的脑袋,当我更改url以匹配uri而不是方法名称时如下:
$.ajax({
type: "POST",
url: "ExtractionService.svc/SubmitExtraction",
data: JSON.stringify(ExtractionData),
contentType: "application/json; charset=utf-8",
dataType: "json",