アプリで SOAP Web サービスを使用しています。次のステートメント (.m ファイル) を使用して要求を行います。
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *soapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?><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/>\"><soap:Body><retLoca xmlns=\"http://www.ctrlbase.nl/cbawebapp>\"><tcUser>112</tcUser></retLoca></soap:Body></soap:Envelope>"];
NSURL *url = [NSURL URLWithString:
@"http://www.ctrlbase.nl/cbawebapp/getLoca.asmx>"];
NSMutableURLRequest *req =
[NSMutableURLRequest requestWithURL:url];
NSString *msgLength =
[NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8"
forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://www.ctrlbase.nl/cbawebapp/retLoca>"
forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength
forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.dimBackground = YES;
HUD.labelText = @"Ophalen van gegevens";
HUD.delegate = self;
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if( theConnection )
{
webData = [NSMutableData data];
}
else
{
NSLog(@"theConnection is NULL");
}
}
-(void) connection:(NSURLConnection *) connection
didReceiveResponse:(NSURLResponse *) response {
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *) connection
didReceiveData:(NSData *) data {
[webData appendData:data];
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc]
initWithBytes: [webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
//---shows the XML---
NSLog(theXML);
if( xmlParser )
{
}
xmlParser = [[NSXMLParser alloc] initWithData:webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
[HUD hide:YES];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ( [elementName isEqualToString:@"retLocaResponse"] ) {
NSLog(@"Log Output%@",[attributeDict objectForKey:@"retLocaResult"]);
NSString *strValue= [attributeDict objectForKey:@"retLocaResult"];
if(strValue != (NSString*)[NSNull null])
{
[chunks addObject:[attributeDict objectForKey:@"retLocaResult"]];
}
else
{
}
recordResults = YES;
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:
(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ( [elementName isEqualToString:@"retLocaResponse"] ) {
NSLog(@"Log array%@",chunks);
[[self tableView]reloadData];
recordResults = NO;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [chunks count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}
cell.textLabel.text =[chunks objectAtIndex:indexPath.row];
return cell;
}
しかし、場所の名前をUITableViewに入れません。何を間違っているのか、これを機能させるために何ができるのか. 申請書を完成させるために、私を助けてください。
どうもありがとう!
Samkit Jain の編集: 配列の「init」でクラッシュします。
ログ:
2013-08-09 00:12:31.631 Ctrlbase[776:c07] リクエストが終了しました 2013-08-09 00:12:31.904 Ctrlbase[776:c07] 完了。受信バイト: 381 2013-08-09 00:12:31.904 Ctrlbase[776:c07] 0640. Home5 Cash & Carry 2013-08-09 00:12:32.028 Ctrlbase[776:c07] ログ出力 (ヌル) 2013-08 -09 00:12:32.159 Ctrlbase[776:c07] * キャッチされていない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: '* -[__NSArrayM insertObject:atIndex:]: オブジェクトを nil にすることはできません'
-
サーバーリクエスト:
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<retLoca xmlns="http://www.ctrlbase.nl/cbawebapp">
<tcUser>string</tcUser>
</retLoca>
</soap:Body>
</soap:Envelope>
サーバーの応答:
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<retLocaResponse xmlns="http://www.ctrlbase.nl/cbawebapp">
<retLocaResult>string</retLocaResult>
</retLocaResponse>
</soap:Body>
</soap:Envelope>