首先也是最重要的一点,WSLD2OBJC太臃肿,无法使用
1) 一般来说,如果消息不加密,SOAP 本身就不安全。如果您将.NET 中的属性与 SOAP v1.0 一起使用,请考虑来自someSOAPmethod 的SOAP 主体:[WebMethod]
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>
Run Code Online (Sandbox Code Playgroud)
%@ 必须与加密数据一起传递以保护 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;
}
Run Code Online (Sandbox Code Playgroud)
上述方法的使用方法:
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
Run Code Online (Sandbox Code Playgroud)
3) 是的,您可以使用 NSXMLParse任何您喜欢的第三方库来绑定 SOAP 请求或取消绑定 SOAP 响应。
| 归档时间: |
|
| 查看次数: |
2271 次 |
| 最近记录: |