我正在调用soap Web服务,这将导致以下错误:
DONE. Received Bytes: 156
<HTML><HEAD><TITLE>Web Service</TITLE></HEAD><BODY><H1>Bad Request</H1><PRE>Error parsing envelope: (3, 13) Whitespace required.</PRE></BODY></HTML>
我正在使用以下是我的代码:
-(IBAction)invokeService
{
NSString *soapFormat = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:dpw=\"http://xmlns.oracle.com/apps/per/soaprovider/plsql/dpw_create_absence_pkg/\n" "xmlns:dpw1=\"http://xmlns.oracle.com/apps/per/soaprovider/plsql/dpw_create_absence_pkg/dpw_create_absence_api/\">\n"
"<soapenv:Header> <dpw:SOAHeader> <!--Optional:--><dpw:Responsibility></dpw:Responsibility> <!--Optional:--> <dpw:RespApplication></dpw:RespApplication><!--Optional:--><dpw:SecurityGroup></dpw:SecurityGroup> <!--Optional:--><dpw:NLSLanguage></dpw:NLSLanguage> <!--Optional:--> <dpw:Org_Id></dpw:Org_Id> </dpw:SOAHeader> </soapenv:Header> <soapenv:Body> <dpw1:InputParameters> <!--Optional:--> <dpw1:PERSON_ID>2</dpw1:PERSON_ID> </dpw1:InputParameters> </soapenv:Body> </soapenv:Envelope>"];
NSLog(@"The request format is %@",soapFormat);
NSURL *locationOfWebService = [NSURL URLWithString:@"http://oracle.techvedika.com:8006/webservices/SOAProvider/plsql/dpw_create_absence_pkg/"];
NSLog(@"web url = %@",locationOfWebService);
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapFormat length]];
[theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://oracle.techvedika.com:8006/webservices/SOAProvider/plsql/dpw_create_absence_pkg/" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
//the below encoding is used to send data over the net
[theRequest setHTTPBody:[soapFormat dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
if (connect)
{
webData = [[NSMutableData alloc]init];
startActivityIndicator;
}
else
{
NSLog(@"No Connection established");
}
}
//NSURLConnection delegate method
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);
xmlParser = [[NSXMLParser alloc]initWithData:webData];
[xmlParser setDelegate: self];
//[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
}
//xml delegates
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
}
在connectionDidFinishLoading中,当我将其转换为字符串时,我得到了156个字节的NSDATA,它给出了以上错误。我要去哪里错了?
当我在Soapclient UI中测试URL时,我得到了o / p如下所示,我将附上屏幕截图以供参考。
最佳答案
您在请求中弄乱了双引号。请改用以下内容。
NSString *soapFormat = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:dpw=\"http://xmlns.oracle.com/apps/per/soaprovider/plsql/dpw_create_absence_pkg/\"\n xmlns:dpw1=\"http://xmlns.oracle.com/apps/per/soaprovider/plsql/dpw_create_absence_pkg/dpw_create_absence_api/\">\n"
"<soapenv:Header> <dpw:SOAHeader> <!--Optional:--><dpw:Responsibility></dpw:Responsibility> <!--Optional:--> <dpw:RespApplication></dpw:RespApplication><!--Optional:--><dpw:SecurityGroup></dpw:SecurityGroup> <!--Optional:--><dpw:NLSLanguage></dpw:NLSLanguage> <!--Optional:--> <dpw:Org_Id></dpw:Org_Id> </dpw:SOAHeader> </soapenv:Header> <soapenv:Body> <dpw1:InputParameters> <!--Optional:--> <dpw1:PERSON_ID>2</dpw1:PERSON_ID> </dpw1:InputParameters> </soapenv:Body> </soapenv:Envelope>"];
关于ios - 解析SOAP时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23782863/