 |
[PHP]
Call ASP.Net Web Services ส่งพารามิเตอร์ไปในเว็บเซอร์วิสไม่ได้ (Error: System.InvalidOperationException: Missing parameter) |
|
 |
|
|
 |
 |
|
ใช้ Web Service ASP.NET แต่พอส่งพารามิเตอร์เข้าไปมันจะเออเร่อ System.InvalidOperationException: Missing parameter
Code (JavaScript)
01. .controller( 'HelloWorld' , function ($scope, $http) {
02. var name = "Jiraphan" ;
03.
04. $http({
05. url: test_websevice + '/HelloWorld' ,
06. method: 'POST' ,
07. data: { 'strName' : name },
08. headers: { 'Content-Type' : 'application/x-www-form-urlencoded; charset=utf-8' }
09. }).then( function successCallback(response) {
10. console.log(response);
11. }, function errorCallback(response) {
12. console.log(response);
13. })
14.
15. });
Code (ASP)
01. using System;
02. using System.Collections.Generic;
03. using System.Linq;
04. using System.Web;
05. using System.Web.Services;
06.
07. namespace WebService1
08. {
09. /// <summary>
10. /// Summary description for Service1
11. /// </summary>
13. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
14. [System.ComponentModel.ToolboxItem(false)]
15. // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
16. // [System.Web.Script.Services.ScriptService]
17. public class Service1 : System.Web.Services.WebService
18. {
19.
20. [WebMethod]
21. public string HelloWorld( String strName)
22. {
23. return "Hello World " + strName + "" ;
24. }
25. }
26. }
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 :
1306 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัว Web Services มันยอมให้เรียกแบบนี้ได้หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2016-09-28 11:54:47 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเป็นแค่การรีเทิร์นค่าอย่างเดียว สามารถใช้โค้ดนี้คะ แต่พอมีพารามิเตอร์มันเออเร่อ Missing parameter เลยไม่รู้ว่าเป็นที่ตัวโค้ด หรือมันส่งพารามิเตอร์ไม่ไปกันแน่
get datetime จากเว็บเซอร์วิส (ไม่มีการส่งพารามิเตอร์)
01. .controller( 'Get_Datetime' , function ($scope, $http) {
02. $http({
03. url: base_url_websv + '/Get_Datetime' ,
04. method: 'POST' ,
05. headers: { 'Content-Type' : 'application/json; charset=utf-8' }
06. }).then( function successCallback(response) {
07. var x2js = new X2JS();
08. var jsonObj = x2js.xml_str2json(response.data);
09. $scope.getdatetime = jsonObj.DataTable.diffgram.NewDataSet.Table[ 'now' ]
10.
11. }, function errorCallback(response) {
12. console.log(response);
13. })
14. })
|
ประวัติการแก้ไข 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 คะ
โค้ดเก่า
1. data: { 'strName' : name }
โค้ดใหม่
1. data: $.param({
2. strName: name
3. })
Code (JavaScript)
01. .controller( 'Check_Login' , function ($scope, $ionicPopup, $timeout, $http) {
02. $scope.HelloWorld = function (strName) {
03. $http({
04. url: test_websevice + '/HelloWorldName' ,
05. method: 'POST' ,
06. data: $.param({
07. strName: name
08. }),
09. headers: { 'Content-Type' : 'application/x-www-form-urlencoded; charset=utf-8' }
10. }).then( function successCallback(response) {
11. console.log(response);
12. }, function errorCallback(response) {
13. console.log(response);
14. });
15. };
16. });
|
ประวัติการแก้ไข 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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|