2012-03-14 5 views
1

アプリケーションでSOAP Webサービスを使用しましたが、適切なxml応答結果がサーバーから取得されませんでしたが、同じWebサービスがAndroid側でうまく動作しています適切なSOAP xml応答。しかし、iPhone側では機能しません。だから、私はどちら側に問題があるのか​​、サーバー側かクライアント側(iPhone側のみ)にはいらない。私もASHTTPRequestを試してみましたが、私は同じ結果を得ています。iPhoneのSOAP XMLレスポンスの問題

これは、NSURL接続を使用してWebサービスを呼び出すためのサンプルコードです

NSString *soapMessage = [NSString stringWithFormat: 
          @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
          @"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" 
          @"<soap:Body>\n" 
          @"<ViewMemberShipPackagesResponse xmlns=\"http://tempuri.org/\">\n" 
          @"</ViewMemberShipPackagesResponse>\n" 
          @"</soap:Body>\n" 
          @"</soap:Envelope>\n"]; 


    NSString* urlString=[NSString stringWithFormat:@"http://aaaaa.com/aaaaaa.asmx"]; 
    NSURL *url = [NSURL URLWithString:urlString]; 

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue:@"http://tempuri.org/ViewMemberShipPackagesResponse" forHTTPHeaderField:@"SOAPAction"]; 
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if(theConnection) 
    { 
     receiveData = [[NSMutableData data] retain]; 
    } 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 
    NSLog(@"didReceiveResponse"); 
    [receiveData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    NSLog(@"didReceiveData"); 
    [receiveData appendData:data]; 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection { 

    NSString *urlDataString = [[NSString alloc] initWithData:receiveData encoding:NSASCIIStringEncoding]; 
    NSLog(@"the urlDataString is %@", urlDataString); 
} 

しかし、私は、サーバーからの適切な石鹸XML応答を取得しておりません。サーバーからこのサンプル出力応答は、

&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Body&gt;&lt;ViewMemberShipPackagesResponse xmlns="http://tempuri.org/"&gt;&lt;ViewMemberShipPackagesResult&gt;6&lt;/ViewMemberShipPackagesResult&gt;&lt;Package&gt;&lt;ID&gt;5&lt;/ID&gt;&lt;Name&gt;1 Month Package&lt;/Name&gt;&lt;DateSpan&gt;1 Month&lt;/DateSpan&gt;&lt;Price&gt;$29.99&lt;/Price&gt;&lt;Description&gt;Test&lt;/Description&gt;&lt;/Package&gt;&lt;Package&gt;&lt;ID&gt;6&lt;/ID&gt;&lt;Name&gt;1 Month Package with Multiple Locations&lt;/Name&gt;&lt;DateSpan&gt;1 Month&lt;/DateSpan&gt;&lt;Price&gt;$89.99&lt;/Price&gt;&lt;Description&gt;This pacakge to have&lt;/Description&gt;&lt;

/Package&gt;&lt;Package&gt;&lt;ID&gt;7&lt;/ID&gt;&lt;Name&gt;12 Month Test Package&lt;/Name&gt;&lt;DateSpan&gt;12 Months&lt;/DateSpan&gt;&lt;Price&gt;$360.00&lt;/Price&gt;&lt;Description&gt;12 Month Package&lt;/Description&gt;&lt;/Package&gt;&lt;Package&gt;&lt;ID&gt;4&lt;/ID&gt;&lt;Name&gt;Andy Test Package&lt;/Name&gt;&lt;DateSpan&gt;12 Months&lt;/DateSpan&gt;&lt;Price&gt;$49.99&lt;/Price&gt;&lt;Description&gt;Test package for a year&lt;/Description&gt;&lt;/Package&gt;&lt;Package&gt;&lt;ID&gt;2&lt;/ID&gt;&lt;Name&gt;Golden Package&lt;/Name&gt;&lt;DateSpan&gt;6 Months&lt;/DateSpan&gt;&lt;Price&gt;$80.00&lt;/Price&gt;&lt;Description&gt;There are many variations of passages of Lorem Ipsum available, but the majority have suffered&lt;/Description&gt;&lt;/Package&gt;&lt;Package&gt;&lt;ID&gt;1&lt;/ID&gt;&lt;Name&gt;Premium Package&lt;/Name&gt;&lt;DateSpan&gt;12 Months&lt;/DateSpan&gt;&lt;Price&gt;$120.00&lt;/Price&gt;&lt;Description&gt;It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.&lt;/Description&gt;&lt;/Package&gt;&lt;/ViewMemberShipPackagesResponse&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;</ViewMembershipPackagesResult></ViewMembershipPackagesResponse> </soap:Body></soap:Envelope>. 

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ViewMembershipPackagesResponse xmlns="http://tempuri.org/"><ViewMembershipPackagesResult xsi:type="xsd:string"> 

私を導いてください。

THanks!

+0

あなたはこれを解決する方法を私に伝えることができますか..? – Kamarshad

答えて

1

変更この:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection { 

     NSString * urlDataString = [[NSString alloc] initWithBytes: [receiveData mutableBytes] length:[receiveData length] encoding:NSUTF8StringEncoding]; 
     NSLog(@"the  urlDataString is %@", urlDataString); 
} 
+0

私はすでにそれを試しましたが、運はありません。それでも同じ結果が出ます。 – Pugal

+0

今編集された回答 – Hector

+0

も同じものを試してみました。 – Pugal