2015-06-29 47 views
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> 

这应该是你所需要的。如果还有其他的东西,我可以把它说出来。我觉得它很小。我一直在把所有这些都放在一起,我知道它可能看起来很波涛汹涌,但我觉得它的大部分都处于工作状态。任何帮助表示赞赏。

+0

修复了我自己的问题。编辑以显示出错的地方。 – Ken

+0

如果您修复了它,您应该创建一个解释您所做的事情的答案,而不是编辑您的问题。这对于其他可能与您具有相同问题的人来说更清楚。我已经回滚你编辑(不要担心,你仍然可以从编辑历史http://stackoverflow.com/posts/31122001/revisions中检索它)。 –

+0

在下面添加了一个答案,解决了我的问题。 – Ken

回答

2

在Ajax调用,我在那里访问的URL,我把方法名如下:

$.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",