2

我的 jQuery 调用的 WCF 服务有问题。“错误 400 错误请求”

这是我的代码:

  1. 界面
  2. 执行
  3. 网页配置
  4. 调用 BoardService 的 Javascript 方法

IBoardService

[ServiceContract]
public interface IBoardService
{
    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    string HelloWorld(string position, string idTask);

董事会服务

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class BoardService : IBoardService
{
    public string HelloWorld(string position, string idTask)
    {
...
        JavaScriptSerializer js = new JavaScriptSerializer();
        return js.Serialize("Column: " + idColumn + " Story: " + idStory + " IdTask: " + idTask);

网页配置

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="EndpBehavior">
            <webHttp/>
        </behavior>
    </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  <services>
      <service behaviorConfiguration="ServiceBehavior" name="App.WebMVC.WCF.BoardService.BoardService">
          <endpoint address="" binding="webHttpBinding" contract="App.WebMVC.WCF.BoardService.IBoardService" behaviorConfiguration="EndpBehavior"/>
      </service>
  </services>
 </system.serviceModel>

jquery.drangdrop.js - javascript 方法

    function Display(id,tempCurrentDrag) {
    var pageUrl = '../../WCF/BoardService.svc'
    $.ajax({
        type: "POST",
        url: pageUrl + "/HelloWorld",
        data: "{'position': '" + id + "', 'idTask': '"+tempCurrentDrag+"'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccessCall,
        error: OnErrorCall
    });

    }
4

0 回答 0