开发者

ASP.NET + AJAX + WebService: string result + out parameter

开发者 https://www.devze.com 2023-01-30 05:14 出处:网络
In my experience I call simple web methods, like this: [WebMethod] public List<string> GetUserListByLetters(string strLetters){ ... }

In my experience I call simple web methods, like this:

[WebMethod]
public List<string> GetUserListByLetters(string strLetters){ ... }

And here is my OnComplete JS-function:

function OnComplete(args) {
    ...
    if (args != "") {
        for (var i = 0; i < args.length; i++) {
            // Do what I need with string in args[i]
        }
    }
    ...
}

For now I would like to have such method:

[WebMethod]
public string GetUserListByCountry(int countryId, out List<User> users)
{ 
    users=null;
    if ( Validate(countryId)==false )
        return "wrong country Id";
    users = Get开发者_StackOverflowUsers(countryId); // returns list of User objects.
    return "";
}

Question1: should "out" parameter work in WS? I saw few article (, for example) where said it is impossible. Question2: if it doesn't work, how should I change method signature to get that workable? Question3: if it works, how could I access data from 'out' parameter?

Thanks.


I will use this approach:

[WebMethod]
public object GetUserListByCountry(int countryId)
{ 
    users=null;
    if ( Validate(countryId)==false )
        return "wrong country Id";
    users = GetUsers(countryId); // returns list of User objects.
    return new {Error="", Users=users};
}

I mean that I will return complex object, its one property will contain usual value for return and another - required data.

0

精彩评论

暂无评论...
验证码 换一张
取 消