HOME > Client Script Forum > Call ASP.Net Web Services ส่งพารามิเตอร์ไปในเว็บเซอร์วิสไม่ได้ (Error: System.InvalidOperationException: Missing parameter)
Call ASP.Net Web Services ส่งพารามิเตอร์ไปในเว็บเซอร์วิสไม่ได้ (Error: System.InvalidOperationException: Missing parameter)
ใช้ Web Service ASP.NET แต่พอส่งพารามิเตอร์เข้าไปมันจะเออเร่อ System.InvalidOperationException: Missing parameter
Code (JavaScript)
.controller('HelloWorld', function($scope, $http) {
var name = "Jiraphan";
//$scope.helloworld = function() {
$http({
url: test_websevice + '/HelloWorld',
method: 'POST',
data: { 'strName': name },
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
}).then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log(response);
})
//}
});
Code (ASP)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(String strName)
{
return "Hello World "+ strName +"";
}
}
}