使用asihttprequest访问Web服务时找不到方法错误

时间:2011-02-08 11:27:27

标签: objective-c web-services soap asihttprequest json-rpc

我已经使用JSON-RPC桥创建了可以从具有ASIHTTPRequest库的Objective-C环境访问的SOAP Web服务。 当我从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];
}

1 个答案:

答案 0 :(得分:1)

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

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