我正在做从 iPhone 向 wcf 服务发送(POST)XML 请求的概念,我知道发送 XML 请求的现象。但是我有从 wcf 服务检索到的 html 数据,我必须发布与请求相同的数据服务。检索 html 数据后,我将其存储在 NSString 变量中,并在请求中传递了该字符串。但我无法发布并收到错误。'反序列化 EService.svc 类型的对象时出错。令牌'[CDATA ['是预期的,但发现'DOCTYPE'。为什么我收到这个错误?
来自服务的 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>glory@i.net</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”。
我哪里出错了以及如何将 html 数据发布到 wcf 服务?
任何帮助都会得到满足..