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)"}}

网络服务:

@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;
}

桥牌类:

public class Bridge {

private UserWS userWS = new UserWS();

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

目标-C 方面:

(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];
}
4

1 回答 1

1

您的 ASIHTTPRequest 实例request是自动释放的。这意味着它会在您的-clickDownloadButton:方法结束后立即被释放,这可能会提前终止您的会话。

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

于 2011-02-25T21:54:29.380 回答