2012-04-25 16 views
0

私はiPhoneアプリを使ってWebサービス接続を行っています。私はiPhone開発にはとても新しいので、次のリンク、iPhoneアプリケーションをasmx soap webserviceに接続する方法

http://www.leesilver.net/1/post/2011/08/calling-a-web-service-from-objective-c.html 

通じしかし、私は、行のNSString *クエリ= AppDelegate.dataで"property 'data' not found on object of type 'AppDelegate'" を次のエラーを取得しています。

以下は、このに関する

-(IBAction)btnDone:(id)sender{ 

    recordResults = FALSE; 
    NSString *query = AppDelegate.data; // Getting the error at this line 
             //property 'data' not found on object of type 'AppDelegate'   
    query = [query stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"]; 
    query = [query stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"]; 

    NSString *soapMessage = [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>\n" 
          "<HelloWorld xmlns=\"http://tempuri.org/\">\n" 
          "<xmlIn>\n" 
          "<![CDATA[%@]]>\n" 
          "</xmlIn>\n" 
          "</HelloWorld>\n" 
          "</soap:Body>\n" 
          "</soap:Envelope>\n", query ]; 

    NSLog(@"%@",soapMessage); 
    NSURL *url = [NSURL URLWithString:@"http://www.xxxxxxx.net/service.asmx"]; 
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
    NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]]; 
    [theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue:@"http://www.xxxxxxxxxxx.net/service.asmx?op=HelloWorld" forHTTPHeaderField:@"SOAPAction"]; 
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Type"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 
    NSLog(@"Message Length..%@",msgLength); 

    NSURLConnection *theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; 

    if(theConnection) 
    { 
     conWebData = [NSMutableData data]; 
    } 
    else 
    { 
     NSLog(@"theConnection is NULL"); 
    } 

} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [conWebData setLength:0]; 
} 
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"ERROR with theConnection"); 
} 
-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"DONE. Received Bytes:%d",[conWebData length]); 
    NSString *theXML = [[NSString alloc]initWithBytes:[conWebData mutableBytes] length:[conWebData length] encoding:NSUTF8StringEncoding]; 
    NSLog(@"%@",theXML); 

    xmlParser = [[NSXMLParser alloc]initWithData:conWebData]; 
    [xmlParser setDelegate:self]; 
    [xmlParser setShouldResolveExternalEntities:YES]; 
    [xmlParser parse]; 
} 

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict 
{ 
    if([elementName isEqualToString:@"HelloWorldResult"]) 
    { 
     if(!soapResults) 
     { 
      soapResults = [[NSMutableString alloc]init]; 
     } 
     recordResults = TRUE; 
    } 
} 

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 
    if(recordResults) 
    { 
     [soapResults appendString:string]; 
    } 
} 

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{ 
    if([elementName isEqualToString:@"HelloWorldResult"]) 
    { 
     recordResults = FALSE; 
     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:soapResults delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     soapResults = nil; 
    } 
} 

すべてのヘルプは高く評価され、私の全体のコードです。 ありがとうございます。

+0

RESTを使用するとコードが短くて速くなります –

+0

@Alex:ここであなたの意見に感謝し、サンプルのRESTコードを見つけようとしました。何か良いリソースやURLがあれば、わかりませんでした。 – ituner

+0

サーバーには、残りのプロトコルが実装されている必要があります。また、xmlでないjsonレスポンスを求めてください –

答えて

0

メッセージ長のヘッダーは「Content-Length」であり、「Content-Type」ではないので、試してみてください: [theRequest addValue:msgLength forHTTPHeaderField:@ "Content-Length"]; の代わりに [theRequest addValue:msgLength forHTTPHeaderField:@ "Content-Type"];アプリケーションサーバは、XMLやJSONは私の「Webサービス」アプリの例を参照してくださいメッセージの応答として返さなければなりませんREST Webサービスの ...

0

こんにちは私のために素晴らしい仕事道具を設立し、http://www.wsdl2code.com

SampleServiceProxy *proxy = [[SampleServiceProxy alloc]initWithUrl:@"YOUR 
      URL" AndDelegate:self]; 

    [proxy GetDouble]; 
    [proxy GetEnum]; 
    [proxy getEnum:kTestEnumTestEnum2]; 
    [proxy GetInt16]; 
    [proxy GetInt32]; 
    [proxy GetInt64]; 
    [proxy GetString]; 
    [proxy getListStrings]; 
関連する問題