Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Wcf服务写入PUT/DELETE方法会使服务崩溃_Jquery_Asp.net_Ajax_Wcf - Fatal编程技术网

Jquery Wcf服务写入PUT/DELETE方法会使服务崩溃

Jquery Wcf服务写入PUT/DELETE方法会使服务崩溃,jquery,asp.net,ajax,wcf,Jquery,Asp.net,Ajax,Wcf,我正在创建一个与数据库交互的web服务,它应该执行CRUD操作。现在,它可以很好地处理read和post操作,WCF服务应该有一个方法,每当页面完成加载以检索所有提供者的列表时,就会从jQuery中调用该方法,但是,当我用这样的方法更新WCF服务时,它可以很好地工作 [OperationContract] [WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFor

我正在创建一个与数据库交互的web服务,它应该执行CRUD操作。现在,它可以很好地处理read和post操作,WCF服务应该有一个方法,每当页面完成加载以检索所有提供者的列表时,就会从jQuery中调用该方法,但是,当我用这样的方法更新WCF服务时,它可以很好地工作

[OperationContract]
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Object PutSupplier(int id, Supplier oParameter)
{
    // Do work
}

当页面加载和插入操作也失败时,发生了一些事情,没有数据返回,我得到了500个内部错误?!。比如,如果整个WCF服务不可见或无法运行

下面是我的其他WCF服务方法和调用jQuery/Ajax的方法

[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public List<Supplier> GetSupplier(int id)
{
    // Add your operation implementation here
    return DbContext.DbContextManager.GetSupplier(id.ToNullableInt());
}
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Supplier PostSupplier(Supplier oParameter)
{
    return DbContext.DbContextManager.PostSupplier(oParameter);
}

<script>
$(function () {
    $.ajax({
        method: 'GET',
        url: '/WebServices/NameService.svc/GetSupplier',
        data: JSON.stringify({ id : 0 }),
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (item) {
            $.each(item, function (i) {
                var _tr = '<tr><td class="readonly-"><input type="text" class="form-control" value="' + item[i].CompanyName + '" style="display:table-cell; width:100%" readonly/></td><td>' +
                    '<button type="button" id="pencilbutton_' + item[i].SupplierId + '"  class="btn btn-success">' +
                    '<span class="glyphicon glyphicon-pencil"></span> Pencil</span></button>' +
                    '<button type="button" id="removebutton_' + item[i].SupplierId + '"  class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove</button></td></tr>';
                $('tbody').append(_tr);
            });
        }
    });
    $('table').on('focus', 'input[type="text"]', function () {
        $(this).removeAttr('readonly');
    });
    $(':button[class*="btn-primary"]').click(function () {
        if (Page_ClientValidate("MyValidationGroup")) {
            $.ajax({
                method: 'POST',
                url: '/WebServices/NameService.svc/PostSupplier',
                data: JSON.stringify({ 'SupplierId': 0, 'CompanyName': $(':text[class="form-control"]').val() }),
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                success: function (item) {
                    var _tr = '<tr><td class="readonly-"><input type="text" class="form-control" value="' + item.CompanyName + '" style="display:table-cell; width:100%" readonly/></td><td>' +
                             '<button type="button" id="pencilbutton_' + item.SupplierId + '"  class="btn btn-success">' +
                             '<span class="glyphicon glyphicon-pencil"></span> Pencil</span></button>' +
                             '<button type="button" id="removebutton_' + item.SupplierId + '"  class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove</button></td></tr>';
                    $('tbody').append(_tr);
                }
            });
        }
    });
});
[运营合同]
[WebInvoke(Method=“GET”,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json)]
公共列表供应商(内部id)
{
//在此处添加您的操作实现
返回DbContext.DbContextManager.GetSupplier(id.ToNullableInt());
}
[经营合同]
[WebInvoke(Method=“POST”,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json)]
公共供应商PostSupplier(供应商参数)
{
返回DbContext.DbContextManager.PostSupplier(opParameter);
}
$(函数(){
$.ajax({
方法:“GET”,
url:“/WebServices/NameService.svc/GetSupplier”,
数据:JSON.stringify({id:0}),
数据类型:“json”,
contentType:'application/json;charset=utf-8',
成功:功能(项目){
$。每个(项目、功能(i){
var_tr=''+
'' +
“铅笔”+
“移除”;
$('tbody')。追加(_tr);
});
}
});
$('table')。在('focus','input[type=“text”]”上,函数(){
$(this.removeAttr('readonly');
});
$(':按钮[类*=“btn主”])。单击(函数(){
如果(第_页ClientValidate(“MyValidationGroup”)){
$.ajax({
方法:“POST”,
url:“/WebServices/NameService.svc/PostSupplier”,
数据:JSON.stringify({'SupplierId':0,'CompanyName':$(':text[class=“form control”]')).val(),
数据类型:“json”,
contentType:'application/json;charset=utf-8',
成功:功能(项目){
var_tr=''+
'' +
“铅笔”+
“移除”;
$('tbody')。追加(_tr);
}
});
}
});
});

我建议启用WCF跟踪(),因为它可能会为您提供更多信息。就PUT和DELETE而言,每当在IIS上安装WebDav模块时,我都会遇到这些HTTP方法的问题,但我得到的是405。似乎是我在web.config文件中设置了一个选项创建了这个,我认为这是因为删除它后一切正常:)
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public List<Supplier> GetSupplier(int id)
{
    // Add your operation implementation here
    return DbContext.DbContextManager.GetSupplier(id.ToNullableInt());
}
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Supplier PostSupplier(Supplier oParameter)
{
    return DbContext.DbContextManager.PostSupplier(oParameter);
}

<script>
$(function () {
    $.ajax({
        method: 'GET',
        url: '/WebServices/NameService.svc/GetSupplier',
        data: JSON.stringify({ id : 0 }),
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (item) {
            $.each(item, function (i) {
                var _tr = '<tr><td class="readonly-"><input type="text" class="form-control" value="' + item[i].CompanyName + '" style="display:table-cell; width:100%" readonly/></td><td>' +
                    '<button type="button" id="pencilbutton_' + item[i].SupplierId + '"  class="btn btn-success">' +
                    '<span class="glyphicon glyphicon-pencil"></span> Pencil</span></button>' +
                    '<button type="button" id="removebutton_' + item[i].SupplierId + '"  class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove</button></td></tr>';
                $('tbody').append(_tr);
            });
        }
    });
    $('table').on('focus', 'input[type="text"]', function () {
        $(this).removeAttr('readonly');
    });
    $(':button[class*="btn-primary"]').click(function () {
        if (Page_ClientValidate("MyValidationGroup")) {
            $.ajax({
                method: 'POST',
                url: '/WebServices/NameService.svc/PostSupplier',
                data: JSON.stringify({ 'SupplierId': 0, 'CompanyName': $(':text[class="form-control"]').val() }),
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                success: function (item) {
                    var _tr = '<tr><td class="readonly-"><input type="text" class="form-control" value="' + item.CompanyName + '" style="display:table-cell; width:100%" readonly/></td><td>' +
                             '<button type="button" id="pencilbutton_' + item.SupplierId + '"  class="btn btn-success">' +
                             '<span class="glyphicon glyphicon-pencil"></span> Pencil</span></button>' +
                             '<button type="button" id="removebutton_' + item.SupplierId + '"  class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove</button></td></tr>';
                    $('tbody').append(_tr);
                }
            });
        }
    });
});