views:

63

answers:

1

Hi there!

I'm currently building an iPhone app based on Gsoap toolkit to connect to a webservice. Everything works fine except when I try to connect to my service after disconnecting and reconnecting 3g on the device, I get :

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

Working through the debugger shows that the error comes from connect() method of socket.h. I don't really understand, when I launch another app like safari, the device is connected to the Internet. And after loading a web page, my app's connection works fine.

Here is the code I'm using :

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

Am I missing any particular flag/option?

A: 

For those who encounter the same issue, I got a solution. Michael Lasmanis has been a huge help for this one. Here is his answer :

this is one of the reasons i no longer recommend gsoap for iphone new iphone developers. gsoap uses the lower bsd sockets and bypasses the higher level iphone apis. it is the higher level api that manage the state of the internet connectivity which is why if you start safari first, then everything works. the easiest workaround is to use nsurlconnection to open a http connect to a well know site before calling gsoap.

Romain