我正在开发一个 iPhone 项目,其中我有一个 wsdl,其中包含方法描述,并且这些方法包含一个 xml。我需要调用 wsdl 中的这些方法来使用soap获取xml并解析它。我已经阅读了很多链接和教程,但无法在 wsdl 中调用该方法。请如果你可以给我一些链接或建议。
user1520309
问问题
1179 次
2 回答
0
您可以使用http://sudzc.com/,它为您提供现成的 WSDL
这是一个 .NET 网站解决方案,它使用 XSLT 将基于 SOAP 的 Web 服务定义 WSDL 文件转换为完整的代码包。生成的代码易于阅读和更新。
虽然 SudzC 支持多个平台,但它的重点是为 iPhone 开发的 Objective-C 库生成代码。
于 2013-01-22T06:12:46.353 回答
0
请尝试此代码。它对我有用。
[注意:GetDictionary 是我在 Web 服务中显示的方法名称。在 url 中,请在下面的部分写下 Web 服务中显示的 url。它应该与您在编码中编写的 url 匹配,否则您将无法获得输出(最好从 Web 服务中复制它)]
-(IBAction)loadData
{
NSString *soapMessage = [NSString stringWithFormat:
@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<SOAP-ENV:Body>\n"
"<GetDictionary></GetDictionary>\n"
"</SOAP-ENV:Body>\n"
"</SOAP-ENV:Envelope>"];
NSURL *url = [NSURL URLWithString:@"http://c70.narolainfotech.local/WCFTest/RestServiceImpl.svc/basic"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"urn:RestServiceImpl/GetDictionary" forHTTPHeaderField:@"soapAction"];
// [theRequest addValue: @"urn:RestServiceImpl/getDataBY_ID" forHTTPHeaderField:@"soapAction"];
[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] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
}
在 connectionDidFinishLoading 中编写以下代码:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *strData = [[NSString alloc]initWithData:webData encoding:NSUTF8StringEncoding];
NSLog(@"result : %@",strData);
NSString *result=nil;
NSString *str;
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
theXML = [theXML stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
theXML = [theXML stringByReplacingOccurrencesOfString:@">" withString:@">"];
theXML = [theXML stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
//NSLog(@"XML from Web-Service ======= \n\n %@",theXML);
NSArray *array=[theXML componentsSeparatedByString:@"<GetDictionaryResult>"];
for(int i=1;i<[array count];i++)
{
str=[array objectAtIndex:i];
NSRange ranfrom=[str rangeOfString:@"</GetDictionaryResult>"];
result =[str substringToIndex:ranfrom.location];
}
NSLog(@"result ::: %@",result);
}
只是希望它会为你工作。:)
于 2013-01-22T06:42:29.050 回答