2013-01-08 5 views
0

아이폰에서 wcf 서비스로 보내는 (POST) XML 요청 개념을하고 XML 요청을 보내는 현상을 알았습니다. 그러나 wcf 서비스에서 가져온 html 데이터가 있고 POST와 동일한 데이터를 POST해야합니다. 요청을 service.After NSString 변수에 저장하고 request.But 메신저에서 POST 및 오류를 가져올 수없는 그 문자열을 전달 HTML 데이터를 검색합니다. 'EService.svc 유형의 객체를 비 직렬화하는 중에 오류가 발생했습니다. 토큰 '[CDATA ['는 예상했지만 'DOCTYPE'이 발견되었습니다. 왜이 오류가 발생합니까? 서비스에서iphone에서 wcf 서비스에 POST 요청?

HTML 응답은 다음과 같이이다 :

(
     { 
     BodyEmailforResult = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
\n<html xmlns=\"http://www.w3.org/1999/xhtml\"> 
\n<head> 
\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> 
\n<title>Untitled Document</title> 
\n</head> 
\n 
\n<body style=\"background:#bdd9ef; padding:20px 0px; margin:0px;\"> 
\n\t<table width=\"700px\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-radius:10px; margin:0px auto; background:white; color:#2222; padding:20px 0px;\" > 
\n 
\n <tr> 
\n \t<td style=\"height:130px; background:#e8e8e8; border-bottom:2px solid #c5c5c5; margin:0px; \" > 
\n  \t<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"> 
\n   \t<tr> 
\n    \t<td width=\"40%\" style=\"padding-left:20px;\" > 
\n\t\t  \t\t<img src=\"http://123.32.34.45/images/logo.png\" /> 
\n     </td> 
\n     <td> 
\n     \t<p style=\"color:#1b1b1b; margin:0px; font-size:14px; font-family:Arial, Helvetica, sans-serif; line-height:20px; text-align:right; padding-right:20px; \" >Visit website</p> 
\n      <p style=\"color:#0459df; margin:0px; font-size:14px; font-family:Arial, Helvetica, sans-serif; line-height:20px; text-align:right; padding-right:20px; text-decoration:underline; \"><a href=\"http://123.32.34.45\" style=\"color:#0459df; font-weight:bold; \" >123.32.34.45</a></p> 
\n     </td> 
\n    </tr> 
\n  \t</table> 
\n  </td> 
\n   
\n </tr> 
\n <tr> 
\n \t<td height=\"20px\" > 
\n   
\n  </td> 
\n </tr> 
\n\t<tr> 
\n \t<td style=\"color:#1b1b1b; font-size:14px; text-align:left; font-family:Arial, Helvetica, sans-serif; line-height:24px; padding-left:20px; padding-right:20px; \" > 
\n  \t<p style=\"margin:0px; line-height:30px; \" >Dear <span style=\"font-weight:bold;\" >Mary</span></p> 
\n    
\n    
\n   <p style=\"margin:0px; line-height:24px; padding-top:10px; \" > 
\n   \tThis is to confirm that we have received your registration request for your Account. We have created a temporary link listed below. You can use this link to activate your user account. 
\n   </p> 
\n       
\n   <p style=\"margin:0px; padding-top:10px; \" >You can <a href=\"123.32.34.45/Verify.aspx?Code=N6zDZK \" style=\"color:#0459df; font-weight:bold;\" >click hear </a> to activate your user account. </p> 
\n    
\n   <p style=\"margin:0px; padding-top:10px;\" >Once you confirm your e-mail account, away to make. Note that use your e-mail and password to sign-in. 
\n 
\n</p> 
\n<p style=\"margin:0px; font-size:14px; font-weight:bold; padding-top:10px;\" >Registration Details :</p> 
\n<p style=\"margin:0px; padding-top:10px;\" >Your registration successfully completed Thanks for your registration</p> 
\n 
\n 
\n<p style=\"margin:0px; font-size:16px; padding-top:30px;\" > 
\nThanks & Regards 
\n</p> 
\n<p style=\"color:#0080b8; margin:0px; font-size:16px; font-weight:bold; padding-top:10px;\" > 
\n 
\n</p> 
\n 
\n 
\n  </td> 
\n </tr> 
\n </table> 
\n  
\n</body> 
\n</html>"; 
    } 
) 

I took this response in string as : 
NSString *bodyofemail=[[arr2 objectAtIndex:0]objectForKey:@"BodyEmailforResult"]; 

and POST request is like this : 

    NSString *url5=[NSString stringWithFormat:@"http://123.32.34.45/EService.svc/SendEmail"]; 
     NSMutableURLRequest *request5=[[[NSMutableURLRequest alloc] init]autorelease]; 
     [request5 setURL:[NSURL URLWithString:url5]]; 
     [request5 setHTTPMethod:@"POST"]; 
     NSString *contentType5=[NSString stringWithFormat:@"text/xml"]; 
     [request5 addValue:contentType5 forHTTPHeaderField:@"Content-Type"]; 
     NSMutableData *postBody5=[NSMutableData data]; 
     [postBody5 appendData:[[NSString stringWithFormat:@"<EmailServiceRequest xmlns=\"http://schemas.datacontract.org/2004/07/\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"]dataUsingEncoding:NSUTF8StringEncoding]]; 
     [postBody5 appendData:[[NSString stringWithFormat:@"<Body>%@</Body>",bodyofemail]dataUsingEncoding:NSUTF8StringEncoding]]; 
     [postBody5 appendData:[[NSString stringWithFormat:@"<FromEmail>[email protected]</FromEmail>"]dataUsingEncoding:NSUTF8StringEncoding]]; 
     [postBody5 appendData:[[NSString stringWithFormat:@"<Subject>%@</Subject>",subjectofemail]dataUsingEncoding:NSUTF8StringEncoding]]; 
     [postBody5 appendData:[[NSString stringWithFormat:@"<ToEmail>%@</ToEmail>",txtemail.text]dataUsingEncoding:NSUTF8StringEncoding]]; 
     [postBody5 appendData:[[NSString stringWithFormat:@"</EmailServiceRequest>>"]dataUsingEncoding:NSUTF8StringEncoding]]; 

    [request5 setHTTPBody:postBody5]; 
    NSHTTPURLResponse *urlResponse5=nil; 
    NSError *error5=nil; 
    NSData *responseData5 = [NSURLConnection sendSynchronousRequest:request5 
                returningResponse:&urlResponse5 
                   error:&error5]; 

    if (responseData5!= NULL) 
    { 
     NSString *rss5 = [[NSString alloc] initWithData:responseData5 
               encoding:NSUTF8StringEncoding ]; 
     NSLog(@"Response Code:%d",[urlResponse5 statusCode]); 
     if([urlResponse5 statusCode ]>=200 && [urlResponse5 statusCode]<300) 
     { 
      NSLog(@"Response:%@",rss5); 
     } 
    } 
    else 
    { 
     NSLog(@"Failed to send request: %@", [error5 localizedDescription]); 
    } 

하지만이 같은 오류가 발생했습니다 : '유형 EService.svc의 객체를 직렬화 복원 오류가 발생했습니다. 토큰 '[CDATA ['는 (는) 예상했지만 'DOCTYPE'이 (가) 발견되었습니다.

내가 잘못 가고 어떻게 wcf 서비스에 html 데이터를 POST 할 수 있습니까? 서비스가 XML 또는 JSON 요청 하나를 수 WebHttpBinding를 사용하도록 구성되지 않는 한

어떤 도움 appeciated 될 것이다 ..

답변

0

WCF 서비스는 일반적으로 soap 요청으로 요청을해야합니다. 서비스 개발자가 비누 XML 만 수락하는지 아니면 일반 XML 또는 JSON을 수락 할 수 있는지를 알아야합니다.

두 경우 모두 이러한 종류의 문제를 해결하는 가장 쉬운 방법은 성공적인 호출 (다른 서비스 클라이언트에서)에서 XML 요청 (비누 또는 아닌)을 캡처하여 XML에 대한 템플릿으로 사용하는 것입니다. JSON) 문자열을 iOS 앱에서 빌드해야합니다.

관련 문제