【问题标题】:Using soap with IOS在 IOS 中使用肥皂
【发布时间】:2013-05-28 05:00:53
【问题描述】:

我计划在企业应用程序中使用WSLD2OBJC 来使用基于 SOAP 的服务。但是 wsdl2objc 的最后一次更新是在 2010 年。

  1. 在企业应用程序中使用 wsdl2objc 是否安全?
  2. 还有其他可靠的组件可用于肥皂解析吗?
  3. 或者我可以使用带有 NSXMLParse 的纯 XML 请求来满足我的需要吗?

【问题讨论】:

  • 您打算在后端使用 .NET、PHP 还是 ruby​​?为什么要使用 SOAP 而不是 REST?
  • 后端在.NET中。

标签: ios objective-c xml soap


【解决方案1】:

首先,WSLD2OBJC 太臃肿而无法使用

1) 一般来说,如果消息没有加密,SOAP 本身是不安全的。如果您在带有 SOAP v1.0 的 .NET 中使用属性 [WebMethod],请考虑来自 someSOAPmethod 的此 SOAP 主体:

POST /WebService/Common.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://example.com/someSOAPmethod"
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<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/\">
 <soap:Body>
  <SomeSOAPmethod xmlns=\"http://example.com/\">
   <encryptedMessage>%@</encryptedMessage> //<-- this is vary, depends on your parameter
  </SomeSOAPmethod>
 </soap:Body>
</soap:Envelope> 

%@ 必须与加密数据一起传递以保护 SOAP。您可以使用任何类型的加密,但我更喜欢AES。为了更加安全,请添加 HTTPS 连接(RSA 加密)。

2) 您可以使用 WSLD2OBJC 构建自己的解析。来自 someSOAPmethod 的示例。

-(NSMutableURLRequest *)encapsulateSOAP:(NSString *)encryptedMessage withSoapMethod:(NSString *)soapMethod andBaseURL:(NSURL *)baseURL
{

    NSString* soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><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/\"><soap:Body><%@ xmlns=\"http://example.com/\"><encryptedMessage>%@</encryptedMessage></%@></soap:Body></soap:Envelope>", soapMethod, encryptedMessage, soapMethod];


    NSString* msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

    NSMutableURLRequest* theRequest = [NSMutableURLRequest requestWithURL:baseURLl];
    [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue:[NSString stringWithFormat:@"%@%@", @"http://example.com/", soapMethod ] forHTTPHeaderField:@"SOAPAction"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    [theRequest setTimeoutInterval:10];

    return theRequest;
}

如何使用上述方法:

    NSString *encryptedMessage = //some encrypted message
    NSString *soapMethod = @"someSOAPmethod";
    NSURL *baseURL = [NSURL urlWithString:@"http://example.com"];
    NSMutableURLRequest *requestQueue = [self encapsulateSOAPRequest:encryptedMessage withSoapMethod:soapMethod andBaseURL:baseURL];
    //then request using AFNetworking, ASIHTTP or your own networking library

3) 是的,您可以使用NSXMLParse 或任何您喜欢的第三方库来绑定 SOAP 请求或取消绑定 SOAP 响应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多