2016-09-23 7 views
0
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
NSString *[email protected]"1"; 
NSString *GetExRequest = [NSString stringWithFormat:@"<SOAP-  ENV:Envelope \n" 
        "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" 
        "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" 
        "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" 
        "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" 
        "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n" 
        "<SOAP-ENV:Header> \n" 
        "<UserName xmlns=\"CH1\">a1</UserName>\n" 
        "<Password xmlns=\"CH2\">a2</Password>\n" 
        "</SOAP-ENV:Header> \n" 
        "<SOAP-ENV:Body> \n" 
        "<NewsGet xmlns=\"http://tempuri.org/\">\n" 
        "<id>%@</id> \n" 
        "</NewsGet> \n" 
        "</SOAP-ENV:Body> \n" 
        "</SOAP-ENV:Envelope>\n", id]; 
NSURL *url = [NSURL URLWithString:@"https:/www.a.com/Service1.svc"]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
NSString *msgLength = [NSString stringWithFormat:@"%d",GetExRequest length]]; 
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue: @"http://tempuri.org/IService1/NewsGet" forHTTPHeaderField:@"Soapaction"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [GetExRequest dataUsingEncoding:NSUTF8StringEncoding]]; 
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
if(theConnection) 
{ 
webData = [[NSMutableData data] init]; 
} 
else 
{ 
NSLog(@"theConnection is NULL"); 
} 
itemArray =[[NSMutableArray alloc] init]; 

} 

-(void)connection:(NSURLConnection *)connection didReceiveData: (NSData *)data 
{ 
[webData appendData:data]; 
} 

こんにちは、私はobjective-c上のWebサービス接続に問題があります。 3G接続では、接続が遅すぎるか、動作しません。しかし、WiFiで、私のアプリは正常に動作します。 3Gの接続は速いですが、私はなぜこの減速が現れるのか理解できません。私は3Gのために余分な何かをする必要がありますか?xcode objective c soap xml 3gが動作しません。

私はbreakpoinをこのセクションに置くと、3G時にはdidReceiveData関数に入ります。しかし、無線LANで、それは常に入力します。

答えて

0

多くのプロジェクトであなたのサーバーが最近応答しているのは、あなたのデバイスで遅い応答が返ってきた理由です。3G接続。

私の回避策は、私の要求に対して明示的に設定されたタイムアウトにデフォルトのタイムアウトを変更することです。

チェックこの

NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:40.0]; 

適切な対応のために、あなたのタイムアウトを使用しています。

関連する問題