如何创建肥皂消息

时间:2011-07-07 06:38:11

标签: iphone

我正在使用soap request / response app。我有登录页面。有用户名和密码。这是我的肥皂消息。

                         NSString *soapMessage = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                         "<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/\">\n"
                         "<soap:Body>\n"
                         "<SignOn xmlns=\"http://10.12.50.99/CUTechWebservices/CuTechWebService.asmx\">\n"

                         "<DeviceID>4A6B740C-0B5B-5F8C-8694-1EC0196C1C67</DeviceID>\n"
                         "<UserID>string</UserID>\n"
                         "<CrID>6</CrID>\n"
                         "<UserPin>string</UserPin>\n"
                         "</SignOn>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n"];    

由于用户ID和密码是用户的差异,我想将文本字段(用户ID和密码)中的值传递给soap消息。

怎么做? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

好以下是一些要遵循的步骤。我不确定您可以使用的确切代码。但请根据您的需要进行修改。

对于呼叫请求执行以下操作:

NSMutableURLRequest *request = [WebAPIRequest buildSOAPRequest:@"WebserviceURL" withPostData:strRequest WebMethod:@"YourWebMethodHereForExample-ValidateUSer"];
Connection *con = [[[Connection alloc]initWithClass:@"getClientResult" withRoot:@"soap:Body" withDelegate:delegate withTag:tag]autorelease];
[[[NSURLConnection alloc]initWithRequest:request delegate:con] autorelease];

BuildDataRequest应该是这样的。

+(NSMutableURLRequest *)buildSOAPRequest:(NSString *)serviceUrl withPostData:(NSString *)dataString WebMethod:(NSString*)strMethod{

NSURL *url = [NSURL URLWithString:serviceUrl];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [dataString length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
if (isRegion==YES)
{
    isRegion = NO;
    [theRequest addValue:[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"SOAP Action1",nil),strMethod] forHTTPHeaderField:@"SOAPAction"];

}else 
{
    [theRequest addValue:[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"SOAP Action",nil),strMethod] forHTTPHeaderField:@"SOAPAction"];
}

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [dataString dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"%@",dataString);

return theRequest;
}

希望得到这个帮助。