Теперь я использовал веб-сервис SOAP в своем приложении, и я не получаю правильные результаты XML-ответа от сервера, но тот же веб-сервис работает нормально на стороне Android, и они получают правильный SOAP-XML-ответ. Но это не работает на стороне iPhone. Так что я не знаю, с какой стороны возникла проблема, на стороне сервера или на стороне клиента (только на стороне iPhone). Я пробовал ASHTTPRequest также, я получаю те же результаты.
это пример кода для вызова веб-службы с использованием соединения NSURL,
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 от сервера. Этот пример выходного ответа от сервера,
<?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">
<?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>6</ViewMemberShipPackagesResult><Package><ID>5</ID><Name>1 Month Package</Name><DateSpan>1 Month</DateSpan><Price>$29.99</Price><Description>Test</Description></Package><Package><ID>6</ID><Name>1 Month Package with Multiple Locations</Name><DateSpan>1 Month</DateSpan><Price>$89.99</Price><Description>This pacakge to have</Description><
/Package><Package><ID>7</ID><Name>12 Month Test Package</Name><DateSpan>12 Months</DateSpan><Price>$360.00</Price><Description>12 Month Package</Description></Package><Package><ID>4</ID><Name>Andy Test Package</Name><DateSpan>12 Months</DateSpan><Price>$49.99</Price><Description>Test package for a year</Description></Package><Package><ID>2</ID><Name>Golden Package</Name><DateSpan>6 Months</DateSpan><Price>$80.00</Price><Description>There are many variations of passages of Lorem Ipsum available, but the majority have suffered</Description></Package><Package><ID>1</ID><Name>Premium Package</Name><DateSpan>12 Months</DateSpan><Price>$120.00</Price><Description>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.</Description></Package></ViewMemberShipPackagesResponse></soap:Body></soap:Envelope></ViewMembershipPackagesResult></ViewMembershipPackagesResponse> </soap:Body></soap:Envelope>.
Пожалуйста, ведите меня.
спасибо!