我目前正在构建一个基于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;
}
我错过了任何特定的标志/选项吗?
答案 0 :(得分:1)
对于那些遇到同样问题的人,我得到了一个解决方案。 Michael Lasmanis对此是一个巨大的帮助。这是他的回答:
这是我不再向iphone新iPhone开发者推荐gsoap的原因之一。 gsoap使用较低的bsd套接字并绕过较高级别的iphone apis。它是管理互联网连接状态的更高级别的api,这就是为什么如果你先启动safari,那么一切正常。最简单的解决方法是在调用gsoap之前使用nsurlconnection打开一个知名站点的http连接。