2016-12-02 64 views
0

我創建一個web應用程序中,我使用下面的Web服務方法名稱不是有效的web服務

[WebMethod] 
[ScriptMethod(UseHttpGet = true)] 
public void insertarea(string comname, string brandname, string zone, string location, string area) 
{ 
    string id = ""; 
    var json = ""; 
    SqlCommand cmdcom = new SqlCommand("select id from companydetails where comname='" + comname + "'", con); 
    con.Open(); 
    SqlDataReader drcom = cmdcom.ExecuteReader(); 
    while (drcom.Read()) 
    { 
     id = drcom["id"].ToString(); 
    } 
    con.Close(); 
    List<object> addarea = new List<object>(); 
    if (brandname != "select") 
    { 
     cmd = new SqlCommand("Insert into companyallot values('" + id + "','" + location + "','" + area + "','" + zone + "','" + brandname + "',NULL,NULL,NULL,NULL,NULL)", con); 
     con.Open(); 
     cmd.ExecuteNonQuery(); 
     json = js.Serialize("Area Added with brandname"); 
     con.Close(); 
    } 
    else 
    { 
     cmd = new SqlCommand("Insert into companyallot values('" + id + "','" + location + "','" + area + "','" + zone + "',Null,Null,Null,Null,Null,Null)", con); 
     con.Open(); 
     cmd.ExecuteNonQuery(); 
     json = js.Serialize("Area Added For All Brands"); 
     con.Close(); 
    } 
    Context.Response.Write("{" + '"' + "info" + '"' + ":" + json + "}"); 
} 

但我不斷收到一個錯誤

System.InvalidOperationException:insertarea Web服務方法名稱無效。 在System.Web.Services.Protocols.HttpServerProtocol.Initialize() 在System.Web.Services.Protocols.ServerProtocolFactory.Create(類型類型,HttpContext的上下文中,請求的HttpRequest,HttpResponse對象響應,布爾& abortProcessing)

我試過並改變了方法名稱幾次,但仍然面臨同樣的錯誤。 有人知道這裏有什麼問題嗎?

這是我angularjs功能

$scope.updatefunction = function (param) { 
    $scope.updateparam = param; 
    console.log($scope.updateparam.comarea); 

    $http.get('/allotcompany.asmx/areaintable', { 
     params: { 
     comname: $scope.mdcomname, 
     brandname: $scope.mdbrandname, 
     zone: $scope.mdzone, 
     location: $scope.location, 
     area: $scope.updateparam.comarea 
     } 
    }).then(function (response) { 
     alert(response.data.info); 
     $scope.gettableinfo(); 
    }); 
} 

回答

1

當我看着你的Angularjs代碼,我看到你所說的「areaintable」方法名$http.get('/allotcompany.asmx/areaintable'

當您將其更改爲$http.get('/allotcompany.asmx/insertarea'

會發生什麼
相關問題