Call Webmethod by ref/out parameters in javascript
up vote
0
down vote
favorite
Here is my webmethod
[WebMethod]
public string CheckService(string name, ref string msg)
{
return "Hello" + name;
}
and this is my ajax call
$(document).ready(function () {
$.ajax({
type: "POST",
url: "<%= ResolveUrl("integrator.asmx/CheckService") %>",
data: '{name: "zakki",msg:"" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data1) {
console.log('', data1.d);
}
});
});It raises an error
Cannot convert object of type 'System.String' to type 'System.String&'
c# asp.net ajax web-services webforms
add a comment |
up vote
0
down vote
favorite
Here is my webmethod
[WebMethod]
public string CheckService(string name, ref string msg)
{
return "Hello" + name;
}
and this is my ajax call
$(document).ready(function () {
$.ajax({
type: "POST",
url: "<%= ResolveUrl("integrator.asmx/CheckService") %>",
data: '{name: "zakki",msg:"" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data1) {
console.log('', data1.d);
}
});
});It raises an error
Cannot convert object of type 'System.String' to type 'System.String&'
c# asp.net ajax web-services webforms
All parameters inWebMethodmust use pass-by-value, you cannot useref(andout) keyword(s) for that.
– Tetsuya Yamamoto
Nov 22 at 7:29
What's the point ofrefin your method?
– SeM
Nov 22 at 7:30
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Here is my webmethod
[WebMethod]
public string CheckService(string name, ref string msg)
{
return "Hello" + name;
}
and this is my ajax call
$(document).ready(function () {
$.ajax({
type: "POST",
url: "<%= ResolveUrl("integrator.asmx/CheckService") %>",
data: '{name: "zakki",msg:"" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data1) {
console.log('', data1.d);
}
});
});It raises an error
Cannot convert object of type 'System.String' to type 'System.String&'
c# asp.net ajax web-services webforms
Here is my webmethod
[WebMethod]
public string CheckService(string name, ref string msg)
{
return "Hello" + name;
}
and this is my ajax call
$(document).ready(function () {
$.ajax({
type: "POST",
url: "<%= ResolveUrl("integrator.asmx/CheckService") %>",
data: '{name: "zakki",msg:"" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data1) {
console.log('', data1.d);
}
});
});It raises an error
Cannot convert object of type 'System.String' to type 'System.String&'
$(document).ready(function () {
$.ajax({
type: "POST",
url: "<%= ResolveUrl("integrator.asmx/CheckService") %>",
data: '{name: "zakki",msg:"" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data1) {
console.log('', data1.d);
}
});
});$(document).ready(function () {
$.ajax({
type: "POST",
url: "<%= ResolveUrl("integrator.asmx/CheckService") %>",
data: '{name: "zakki",msg:"" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data1) {
console.log('', data1.d);
}
});
});c# asp.net ajax web-services webforms
c# asp.net ajax web-services webforms
edited Nov 22 at 8:18
Tetsuya Yamamoto
13.9k41939
13.9k41939
asked Nov 22 at 7:25
Zakki Ur Rehman
32
32
All parameters inWebMethodmust use pass-by-value, you cannot useref(andout) keyword(s) for that.
– Tetsuya Yamamoto
Nov 22 at 7:29
What's the point ofrefin your method?
– SeM
Nov 22 at 7:30
add a comment |
All parameters inWebMethodmust use pass-by-value, you cannot useref(andout) keyword(s) for that.
– Tetsuya Yamamoto
Nov 22 at 7:29
What's the point ofrefin your method?
– SeM
Nov 22 at 7:30
All parameters in
WebMethod must use pass-by-value, you cannot use ref (and out) keyword(s) for that.– Tetsuya Yamamoto
Nov 22 at 7:29
All parameters in
WebMethod must use pass-by-value, you cannot use ref (and out) keyword(s) for that.– Tetsuya Yamamoto
Nov 22 at 7:29
What's the point of
ref in your method?– SeM
Nov 22 at 7:30
What's the point of
ref in your method?– SeM
Nov 22 at 7:30
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The short answer is: You cannot use pass-by-reference (with ref/out keywords) for parameters in a method marked with [WebMethod] attribute.
Here is the reason that explains why & added for second System.String type in exception message, taken from this reference:
The key to decoding the source of this message is the "&" located in
the end of the text. This is the syntax used when passing a parameter
to a function BYREF (By-Reference) & used in
C-Notation to indicate "pass the AddressOf" variable name. Even if you coded
the WebService in C#/VB.NET, Microsoft will convert/compile it in C type
notation when it outputs it as an assembly.
Therefore, all parameters inside a method which uses [WebMethod] attribute must use pass-by-value, by removing ref keyword:
[WebMethod]
public string CheckService(string name, string msg)
{
// return string here
}
yes now it is working
– Zakki Ur Rehman
Nov 22 at 11:09
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The short answer is: You cannot use pass-by-reference (with ref/out keywords) for parameters in a method marked with [WebMethod] attribute.
Here is the reason that explains why & added for second System.String type in exception message, taken from this reference:
The key to decoding the source of this message is the "&" located in
the end of the text. This is the syntax used when passing a parameter
to a function BYREF (By-Reference) & used in
C-Notation to indicate "pass the AddressOf" variable name. Even if you coded
the WebService in C#/VB.NET, Microsoft will convert/compile it in C type
notation when it outputs it as an assembly.
Therefore, all parameters inside a method which uses [WebMethod] attribute must use pass-by-value, by removing ref keyword:
[WebMethod]
public string CheckService(string name, string msg)
{
// return string here
}
yes now it is working
– Zakki Ur Rehman
Nov 22 at 11:09
add a comment |
up vote
1
down vote
accepted
The short answer is: You cannot use pass-by-reference (with ref/out keywords) for parameters in a method marked with [WebMethod] attribute.
Here is the reason that explains why & added for second System.String type in exception message, taken from this reference:
The key to decoding the source of this message is the "&" located in
the end of the text. This is the syntax used when passing a parameter
to a function BYREF (By-Reference) & used in
C-Notation to indicate "pass the AddressOf" variable name. Even if you coded
the WebService in C#/VB.NET, Microsoft will convert/compile it in C type
notation when it outputs it as an assembly.
Therefore, all parameters inside a method which uses [WebMethod] attribute must use pass-by-value, by removing ref keyword:
[WebMethod]
public string CheckService(string name, string msg)
{
// return string here
}
yes now it is working
– Zakki Ur Rehman
Nov 22 at 11:09
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The short answer is: You cannot use pass-by-reference (with ref/out keywords) for parameters in a method marked with [WebMethod] attribute.
Here is the reason that explains why & added for second System.String type in exception message, taken from this reference:
The key to decoding the source of this message is the "&" located in
the end of the text. This is the syntax used when passing a parameter
to a function BYREF (By-Reference) & used in
C-Notation to indicate "pass the AddressOf" variable name. Even if you coded
the WebService in C#/VB.NET, Microsoft will convert/compile it in C type
notation when it outputs it as an assembly.
Therefore, all parameters inside a method which uses [WebMethod] attribute must use pass-by-value, by removing ref keyword:
[WebMethod]
public string CheckService(string name, string msg)
{
// return string here
}
The short answer is: You cannot use pass-by-reference (with ref/out keywords) for parameters in a method marked with [WebMethod] attribute.
Here is the reason that explains why & added for second System.String type in exception message, taken from this reference:
The key to decoding the source of this message is the "&" located in
the end of the text. This is the syntax used when passing a parameter
to a function BYREF (By-Reference) & used in
C-Notation to indicate "pass the AddressOf" variable name. Even if you coded
the WebService in C#/VB.NET, Microsoft will convert/compile it in C type
notation when it outputs it as an assembly.
Therefore, all parameters inside a method which uses [WebMethod] attribute must use pass-by-value, by removing ref keyword:
[WebMethod]
public string CheckService(string name, string msg)
{
// return string here
}
answered Nov 22 at 7:38
Tetsuya Yamamoto
13.9k41939
13.9k41939
yes now it is working
– Zakki Ur Rehman
Nov 22 at 11:09
add a comment |
yes now it is working
– Zakki Ur Rehman
Nov 22 at 11:09
yes now it is working
– Zakki Ur Rehman
Nov 22 at 11:09
yes now it is working
– Zakki Ur Rehman
Nov 22 at 11:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425791%2fcall-webmethod-by-ref-out-parameters-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
All parameters in
WebMethodmust use pass-by-value, you cannot useref(andout) keyword(s) for that.– Tetsuya Yamamoto
Nov 22 at 7:29
What's the point of
refin your method?– SeM
Nov 22 at 7:30