0
我正在开发一个应用程序,我需要使用WSDL格式的SOAP webservice。如何在ios中使用SOAP服务进行身份验证?
但它需要在使用服务之前进行身份验证。
我不知道如何使用SOAP服务进行身份验证。
我曾尝试这样的代码: -
-(void)callAPI
{
NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<wsdl:definitions name=\"hubbuchUser\" targetNamespace=\"http://XXX.yy.com/soap/hubbuch/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:tns=\"http://XXX.yy.com/soap/hubbuch/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\">\n" "<wsdl:types></wsdl:types>\n" "<wsdl:binding name=\"hubbuchUserBinding\" type=\"tns:hubbuchUserPortType\">"
"<soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" />"
"<wsdl:operation name=\"isValidDVN\">"
"<soap:operation soapAction=\"http://XXX.yy.com/soap/hubbuch/isValidDVN\" />"
"<wsdl:input>"
"<soap:body use=\"literal\" namespace=\"http://XXX.yy.com/soap/hubbuch/\" />"
"</wsdl:input>"
"<wsdl:output>"
"<soap:body use=\"literal\" namespace=\"http://XXX.yy.com/soap/hubbuch/\" />"
"</wsdl:output>"
"</wsdl:operation>"
"</wsdl:binding>"
"</wsdl:definitions>"];
NSURL *url = [NSURL URLWithString:@"http://XXX.yy.com/soap/hubbuch/hubbuchUser.wsdl"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection =[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [NSMutableData data] ;
NSLog(@"Problem");
}
else
{
NSLog(@"theConnection is NULL");
}
}
-(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");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes:
[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"xml is- %@ ", theXML);
NSData *myData = [theXML dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:myData];
// Don't forget to set the delegate!
xmlParser.delegate = self;
// Run the parser
[xmlParser parse];
}
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qName attributes:(NSDictionary *)attributeDict
{
//curDescription = [[NSString alloc]init];
NSLog(@"attributeDict : %@",attributeDict);
NSLog(@"qName1 : %@",qName);
NSLog(@"elementName1 : %@",elementName);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
//curDescription = string;
NSLog(@"string : %@",string);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
//NSLog(@"3 : %@",curDescription);
NSLog(@"qName2 : %@",qName);
NSLog(@"elementName2 : %@",elementName);
}
我怎样才能做到这一点?
谢谢。使用这样的附加标签与数据库名称的NSString变量
你尝试过什么,有什么代码与我们或做分享任何研究? –
你可以请与我们分享一些细节信息?因为iOS不支持所有SOAP服务。 – 2014-03-04 09:31:29
@HappyCoding我编辑了我的问题。请检查。 – AtWork