iOS客户端如何解析带附件的SOAP消息,
------=_Part_6_5403095.1405994905551
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <[email protected]><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><ns1:downFilePointResponse xmlns:ns1="http://service.sjjk.uniwin.com"><ns1:out ns2:mimeType="application/octet-stream" xmlns:ns2="http://www.w3.org/2004/11/xmlmime"><Include href="cid:1405994905549131484943388@http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2004/08/xop/include" /></ns1:out></ns1:downFilePointResponse></soap:Body></soap:Envelope>
------=_Part_6_5403095.1405994905551
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <1405994905549131484943388@http://www.w3.org/2001/XMLSchema>
------=_Part_6_5403095.1405994905551--
这是调用webservice服务接口返回的数据不知道怎么解析,有哪位大神能帮忙解决一下。
------=_Part_6_5403095.1405994905551
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <[email protected]><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><ns1:downFilePointResponse xmlns:ns1="http://service.sjjk.uniwin.com"><ns1:out ns2:mimeType="application/octet-stream" xmlns:ns2="http://www.w3.org/2004/11/xmlmime"><Include href="cid:1405994905549131484943388@http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2004/08/xop/include" /></ns1:out></ns1:downFilePointResponse></soap:Body></soap:Envelope>
------=_Part_6_5403095.1405994905551
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <1405994905549131484943388@http://www.w3.org/2001/XMLSchema>
------=_Part_6_5403095.1405994905551--
这是调用webservice服务接口返回的数据不知道怎么解析,有哪位大神能帮忙解决一下。
头文件:
#import <UIKit/UIKit.h>@interface BIDViewController : UIViewController <NSXMLParserDelegate>
{
NSURLConnection *theConnection;
NSMutableData *webData;
NSXMLParser *xmlParser;
NSMutableString *soapResults;
BOOL recordResults;
}
- (IBAction)RequestZoneTime:(UIButton *)sender;
@property (strong, nonatomic) IBOutlet UILabel *requestTime;
@end.m文件:#import "BIDViewController.h"@interface BIDViewController ()@end@implementation BIDViewController
@synthesize requestTime;- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}- (IBAction)RequestZoneTime:(UIButton *)sender
{
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">\n"
"<soap:Body>\n"
"<LocalTimeByZipCode xmlns=\"http://www.ripedev.com/\">"
"<ZipCode>12345</ZipCode>\n"
"</LocalTimeByZipCode>\n"
"</soap:Body>\n"
"</soap:Envelope>\n"];
NSString *address =@"http://www.ripedevelopment.com/webservices/LocalTime.asmx";
NSURL* url = [NSURL URLWithString:address];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest addValue: @"text/xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest addValue: @"http://www.ripedev.com/LocalTimeByZipCode"forHTTPHeaderField:@"SOAPAction"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [NSMutableData data];
}
else
{
NSLog(@"theConnection is NULL");
}
[theConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
NSLog(@"connection: didReceiveResponse:1");
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
NSLog(@"connection: didReceiveData:2");
}-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
}-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"3 DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"received data=%@", theXML);
xmlParser = [[NSXMLParser alloc] initWithData:webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
}-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI
qualifiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict
{
NSLog(@"4 parser didStarElemen: namespaceURI: attributes:%@", elementName);
if( [elementName isEqualToString:@"LocalTimeByZipCodeResult"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
recordResults =YES;
}
}-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog(@"5 parser: foundCharacters:");
if(recordResults)
{
[soapResults appendString: string];
}
}-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(@"6 parser: didEndElement:");
if( [elementName isEqualToString: @"LocalTimeByZipCodeResult"])
{
recordResults =FALSE;
NSLog(@"receivedResult timezone=%@",soapResults);
requestTime.text = soapResults; NSLog(@"hoursOffset result");
}
}- (void)parserDidStartDocument:(NSXMLParser *)parser
{
NSLog(@"-------------------start--------------");
}- (void)parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(@"-------------------end--------------");
}
@end看懂了上面的代码就没有问题了。
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <[email protected]><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><ns1:getFileLengthResponse xmlns:ns1="http://service.sjjk.uniwin.com"><ns1:out>189999</ns1:out></ns1:getFileLengthResponse></soap:Body></soap:Envelope>
------=_Part_42_12403951.1406169795632--
我就是不知道怎么去处理这些分隔符,就是这个参数boundary