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&'









share|improve this question
























  • 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















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&'









share|improve this question
























  • 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













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&'









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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
















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












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
}





share|improve this answer





















  • yes now it is working
    – Zakki Ur Rehman
    Nov 22 at 11:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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
}





share|improve this answer





















  • yes now it is working
    – Zakki Ur Rehman
    Nov 22 at 11:09















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
}





share|improve this answer





















  • yes now it is working
    – Zakki Ur Rehman
    Nov 22 at 11:09













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
}





share|improve this answer












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
}






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Lallio

Futebolista

Jornalista