2013-01-08 6 views
0

Je fais le concept d'envoi de requête XML (POST) de l'iPhone au service wcf et je connaissais le phénomène d'envoi d'une requête XML. Mais j'ai des données html que j'ai récupérées depuis wcf et je dois POST les mêmes données que demande de service.Après avoir récupéré les données html je st stocker dans la variable NSString et passé cette chaîne dans request.But je ne suis pas capable de POST et d'obtenir une erreur. 'Une erreur s'est produite lors de la désérialisation de l'objet de type EService.svc. Le jeton '[CDATA [' était prévu mais trouvé 'DOCTYPE'. Pourquoi j'obtiens cette erreur?Demande POST de l'iphone au service wcf?

réponse Html du service est comme ceci:

(
     { 
     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]); 
    } 

Mais je me suis erreur comme ceci: «Il y avait une erreur désérialisation l'objet de type EService.svc. Le jeton '[CDATA [' était attendu mais a trouvé 'DOCTYPE'.

Où je me trompe et comment POSTER des données html au service wcf?

Toute aide serait appeciated ..

Répondre

0

Un service WCF nécessite généralement des demandes d'être soap demandes à moins que le service a été configuré pour utiliser WebHttpBinding qui permet soit des demandes XML ou JSON. Vous devriez savoir à partir des développeurs de service si le service n'accepte que du code XML ou s'il peut accepter du XML ou du JSON. Dans les deux cas, le moyen le plus simple de résoudre ce type de problème consiste à capturer les requêtes XML (appelantes ou non) d'un appel réussi (d'un autre client de service) et à utiliser ces messages comme modèle pour le XML (ou JSON) que vous devez créer dans votre application iOS.