使用 asihttprequest 访问 Web 服务时出现方法未找到错误

发布于 2024-10-16 06:49:32 字数 2101 浏览 2 评论 0原文

我创建了 SOAP Web 服务,可以使用 JSON-RPC 桥接器通过 ASIHTTPRequest 库从 Objective-C 环境进行访问。 当我从 JavaScript 测试它时,一切正常。但是从 Objective-C 中我得到了一个错误

 {"id":2,"error":{"code":591,"msg":"method not found (session may have timed out)"}}

Web Service:

@WebService() 
public class UserWS {

/**
 * User data list - id, first name, last name, service number, username
 */
/**
 * Provides web service to get current user with waiter role data.
 */
@WebMethod(operationName = "getUsers")
public String[][] getUsers() {
    String[][] userDara = null;
    try {
        Context context = POSNamingService.getContext();
        Users us = (Users) context.lookup("business.Users");
        List<User> users = us.getWaiterUsers();
        userDara = new String[users.size()][5];
        for (int i = 0; i < userDara.length; i++) {
            User user = users.get(i);
            userDara[i][0] = String.valueOf(user.getUserNo());
            userDara[i][1] = user.getFirstName();
            userDara[i][2] = user.getLastName();
            userDara[i][3] = user.getServiceNo();
            userDara[i][4] = user.getLogin();
        }
    } catch (NamingException ex) {
        Logger.getLogger(UserWS.class.getName()).log(Level.SEVERE, null, ex);
    }
    return userDara;
}

Bridge class:

public class Bridge {

private UserWS userWS = new UserWS();

public String[][] getUsers(int i) {
    return userWS.getUsers();
}

Objecitive-C side:

(IBAction)clickDownloadButton:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://10.200.0.24:1445/TestRPC-war/JSONRPC"];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
NSString *sendData = [NSString stringWithFormat:@"{\"method\": \"getUsers\"}"];
request appendPostData:[sendData dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"GET"];
[request setDelegate:self];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request setTimeOutSeconds:60]; 
[request startAsynchronous];
}

I've created SOAP web service that would be accessible from Objective-C environment with ASIHTTPRequest library using JSON-RPC bridge .
When I tested it from JavaScript everything where OK. But from Objective-C I got an error

 {"id":2,"error":{"code":591,"msg":"method not found (session may have timed out)"}}

Web Service:

@WebService() 
public class UserWS {

/**
 * User data list - id, first name, last name, service number, username
 */
/**
 * Provides web service to get current user with waiter role data.
 */
@WebMethod(operationName = "getUsers")
public String[][] getUsers() {
    String[][] userDara = null;
    try {
        Context context = POSNamingService.getContext();
        Users us = (Users) context.lookup("business.Users");
        List<User> users = us.getWaiterUsers();
        userDara = new String[users.size()][5];
        for (int i = 0; i < userDara.length; i++) {
            User user = users.get(i);
            userDara[i][0] = String.valueOf(user.getUserNo());
            userDara[i][1] = user.getFirstName();
            userDara[i][2] = user.getLastName();
            userDara[i][3] = user.getServiceNo();
            userDara[i][4] = user.getLogin();
        }
    } catch (NamingException ex) {
        Logger.getLogger(UserWS.class.getName()).log(Level.SEVERE, null, ex);
    }
    return userDara;
}

Bridge class:

public class Bridge {

private UserWS userWS = new UserWS();

public String[][] getUsers(int i) {
    return userWS.getUsers();
}

Objecitive-C side:

(IBAction)clickDownloadButton:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://10.200.0.24:1445/TestRPC-war/JSONRPC"];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
NSString *sendData = [NSString stringWithFormat:@"{\"method\": \"getUsers\"}"];
request appendPostData:[sendData dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"GET"];
[request setDelegate:self];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request setTimeOutSeconds:60]; 
[request startAsynchronous];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神仙妹妹 2024-10-23 06:49:32

您的 ASIHTTPRequest 实例 request 已自动释放。这意味着一旦您的 -clickDownloadButton: 方法结束,它就会被释放,这可能会提前终止您的会话。

相反,您应该将 request 设为一个实例变量,在此处的方法中分配它(但不要自动释放它),然后在请求完成时释放它。

Your ASIHTTPRequest instance request is autoreleased. That means that it will be deallocated pretty much as soon as your -clickDownloadButton: method ends, which is probably terminating your session early.

Instead, you should make request an instance variable, allocate it within your method here (but don't autorelease it), then release it when the request has completed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文