【问题标题】:handling soap envelope in objective C在目标 C 中处理肥皂信封
【发布时间】:2012-10-09 12:36:05
【问题描述】:

我正在尝试通过 sudzc.com 在 iOS 中访问 SOAP Web 服务。看来我得到了肥皂信封作为回报。但我不确定如何处理结果。我可以以某种方式将结果放入 NSDictionary 中还是如何进行?

    - (void)run {
// Create the service
SDZDevices2Api* service = [SDZDevices2Api service];
service.logging = YES;
    // Returns NSString*. (added searchstring and max count values)
[service LocationFindSimple:self action:@selector(LocationFindSimpleHandler:) SearchString: @"Vejle" Max: 1 BankId: [NSMutableArray array] BankName: [NSMutableArray array] Id: [NSMutableArray array] Name: [NSMutableArray array] Icon: [NSMutableArray array] Zip: [NSMutableArray array] Attributes: [NSMutableArray array]];
   }

// Handle the response from LocationFindSimple.

- (void) LocationFindSimpleHandler: (id) value {

// Handle errors
if([value isKindOfClass:[NSError class]]) {
    NSLog(@"%@", value);
    return;
}

// Handle faults
if([value isKindOfClass:[SoapFault class]]) {
    NSLog(@"%@", value);
    return;
}

// Do something with the NSString* result
  NSString* result = (NSString*) value;
    NSLog(@"LocationFindSimple returned the value: %@", result);
}

这是日志消息:

http://pastebin.com/JycGq4Du

【问题讨论】:

  • 只是好奇,为什么要使用 SOAP?在我看来,SOAP 对于移动环境来说太重了。你看过 REST 做事的方法吗? (除非您的业务限制阻止您使用 SOAP)
  • 是的,这是业务限制,这里的一切都在 .Net 框架内(据我了解,在 VB 中编写时 SOAP 非常容易使用)。我希望这可以工作,如果不是我想我必须研究其他格式。还没有真正研究过 REST。它被认为是最佳实践,还是 JSON 也是一种可能性?
  • 几乎所有移动环境(几乎所有以 Web 服务为中心的应用程序)都使用 REST 作为其轻量级负载。 REST 可以同时支持 XML 和 JSON,并且 JSON 被认为是其轻量级和对象表示法的最佳实践(XML 可以完成的事情,但很痛苦)。我最近做了一个WCF REST Service Application 的工作,它的环境有点过时并且有效(我不得不推动我的老板采用它)。它适用于 .NET 4.0,但我认为它也适用于 3.5。如果时间不是主要限制,我建议切换(当有效负载变大时很有用)
  • 听起来很合理。老板对使用 JSON 不屑一顾,所以会牢记这一点。

标签: iphone soap nsstring sudzc


【解决方案1】:

我帮助了其他人:Here

if( [value isKindOfClass:[NSError class]] || [value isKindOfClass:[SoapFault class]] ) 
{

NSLog(@"%@", [value description]);
return;
}

// Verify we're a dictionary
if( ![value isKindOfClass:[NSDictionary class]] ) {

NSLog(@"ERROR: Response not a dictionary");
return;
}

NSDictionary* dict = (NSDictionary*)value;
NSDictionary* resp = [dict objectForKey:@"E_AN"];
if( ( resp == nil ) || ![resp isKindOfClass:[NSDictionary class]] ) {

NSLog(@"ERROR: E_AN not a dictionary");
return;
}
dict = [resp objectForKey:@"item"];
if( ( dict == nil ) || ![dict isKindOfClass:[NSDictionary class]] ) {

NSLog(@"ERROR: item not a dictionary");
return;
}
resp = [dict objectForKey:@"MANDT"];
if( ( resp == nil ) || ![resp isKindOfClass:[NSDictionary class]] ) {

NSLog(@"ERROR: MANDT not a dictionary");
return;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多