1

我目前正在构建一个基于Gsoap工具包的 iPhone 应用程序以连接到 Web 服务。一切正常,除非我在设备上断开并重新连接 3g 后尝试连接到我的服务,我得到:

SOAP 1.1 fault: SOAP-ENV:Client [no subcode]
"Connection refused"
Detail: connect failed in tcp_connect()

通过调试器工作表明错误来自connect(). socket.h我真的不明白,当我启动另一个应用程序(如 safari)时,该设备已连接到 Internet。加载网页后,我的应用程序连接正常。

这是我正在使用的代码:

//GSoap initialization
    struct soap soap; 
    soap_init(&soap);
    soap.connect_timeout = 0;  
    soap.send_timeout = 0; 
    soap.recv_timeout = 0;


// objects request & response
// struct types can be foundin soapStub.h
struct _ns1__GetAuthentification requete;
struct _ns1__GetAuthentificationResponse reponse;

// init request
requete.ConnectPass = (char *) [connectPass UTF8String];
requete.Login = (char *) [login UTF8String];
requete.Password = (char *) [password UTF8String];
requete.soap = &soap;

// request callback. returns SOAP_OK if something has been returned
if(soap_call___ns1__GetAuthentification(&soap,NULL,NULL, &requete,&reponse) == SOAP_OK){

    //then we build the result
    NSLog(@"Yay!");

    soap_end(&soap); // remove deserialized data and clean up
    soap_done(&soap); // detach the gSOAP environment

    return authResult;

}
else {

    //NSLog(@"Soap Error : GetAuthentification");
    // We try to see if there's any problem. @catch statements are here just to keep note of the concerned
    // exceptions for each request. No utility for the code.
    @try {
        [self processFault:&soap];
    }
    @catch (MMWrongId * e) {
        @throw e;
    }
    @catch (MMConnectionFailed * e) {
        @throw e;
    }
    @catch (MMGetAuthentificationFault * e) {
        @throw e;
    }


    return nil;
}

我是否缺少任何特定的标志/选项?

4

1 回答 1

1

对于那些遇到同样问题的人,我得到了解决方案。Michael Lasmanis对此提供了巨大的帮助。这是他的回答:

这是我不再向 iphone 新 iphone 开发人员推荐 gsoap 的原因之一。gsoap 使用较低级别的 bsd 套接字并绕过较高级别的 iphone api。它是管理互联网连接状态的更高级别的 api,这就是为什么如果您首先启动 safari,那么一切正常。最简单的解决方法是在调用 gsoap 之前使用 nsurlconnection 打开与知名站点的 http 连接。

于 2010-08-11T18:20:00.697 回答