 |
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 +"";
}
}
}
Tag : HTML/CSS, JavaScript, Web Service
|
ประวัติการแก้ไข 2016-09-28 10:41:21 2016-09-28 10:42:54 2016-09-28 10:43:36
|
 |
 |
 |
 |
Date :
2016-09-28 10:39:39 |
By :
znorei |
View :
1388 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัว Web Services มันยอมให้เรียกแบบนี้ได้หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2016-09-28 11:54:47 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเป็นแค่การรีเทิร์นค่าอย่างเดียว สามารถใช้โค้ดนี้คะ แต่พอมีพารามิเตอร์มันเออเร่อ Missing parameter เลยไม่รู้ว่าเป็นที่ตัวโค้ด หรือมันส่งพารามิเตอร์ไม่ไปกันแน่
get datetime จากเว็บเซอร์วิส (ไม่มีการส่งพารามิเตอร์)
.controller('Get_Datetime', function($scope, $http) {
$http({
url: base_url_websv + '/Get_Datetime',
method: 'POST',
headers: {'Content-Type': 'application/json; charset=utf-8'}
}).then(function successCallback(response) {
var x2js = new X2JS();
var jsonObj = x2js.xml_str2json(response.data);
$scope.getdatetime = jsonObj.DataTable.diffgram.NewDataSet.Table['now']
//console.log(jsonObj);
}, function errorCallback(response) {
console.log(response);
})
})
|
ประวัติการแก้ไข 2016-09-28 13:08:59 2016-09-28 13:11:00 2016-09-28 13:11:27
 |
 |
 |
 |
Date :
2016-09-28 12:59:15 |
By :
znorei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้ว ขอบคุณ mr.win มาก ๆ คะ 
|
 |
 |
 |
 |
Date :
2016-09-28 13:38:43 |
By :
znorei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สรุปเป็นเพราะอะไรครับ ชื่อ Parameters ผิดหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2016-09-28 13:46:55 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ตรง data คะ
โค้ดเก่า
data: { 'strName': name }
โค้ดใหม่
data: $.param({
strName: name
})
Code (JavaScript)
.controller('Check_Login', function($scope, $ionicPopup, $timeout, $http) {
$scope.HelloWorld = function(strName) {
$http({
url: test_websevice + '/HelloWorldName',
method: 'POST',
data: $.param({
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);
});
};
});
|
ประวัติการแก้ไข 2016-09-28 14:01:11 2016-09-28 14:01:18
 |
 |
 |
 |
Date :
2016-09-28 14:00:16 |
By :
znorei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เยี่ยมเลยครับ 
|
 |
 |
 |
 |
Date :
2016-09-29 15:27:32 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|