<WebMethod()> attribute changes from 2.0 to 3.5
I have a method that looks like:
<W开发者_运维知识库ebMethod()> _
Public Function Search(ByVal q As String) As String
Updating from .net 2.0 to 3.5 appears to have broken this.
We're doing data.split() on the value returned, and that's generating a error - it looks like the value returned is now a json structure, not a simple string.
Is there a way to revert to the prior behavior?
You'll have to import System.Web.Script.Services
Then, try adding this attribute:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _
How are you calling the web method? Through javascript?
We had a similar issue. With the basic setup of Webmethod and jquery ajax call with 2.0 it returns a string (type string in js) or string array (type object in js), in 3.5 it always returns an object and the actual data returned is under .d when returning a primitive like a string or string array.
My best solution so far was a javascript method to check for .d.
function getResponse(r){
if(r.d!=null){
return r.d;
}else{
return r;
}
}
I have to support both the 2.0 and 3.5 calls for the transition and would rather not have to expend too much energy as 2.0 will be gone soon.
But I would rather a better solution.
精彩评论