Iphone 如何创建soap消息

Iphone 如何创建soap消息,iphone,Iphone,我正在使用soap请求/响应应用程序。我有一个登录页面。有用户id和密码。这是我的soap消息 NSString *soapMessage = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<soap:Envelope xmlns:xsi=\"http://www.w3.o

我正在使用soap请求/响应应用程序。我有一个登录页面。有用户id和密码。这是我的soap消息

                         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"];    
NSString*soapMessage=[NSString stringWithFormat:@“\n”
“\n”
“\n”
“\n”
“4A6B740C-0B5B-5F8C-8694-1EC0196C1C67\n”
“字符串\n”
“6\n”
“字符串\n”
“\n”
“\n”
“\n”];
由于用户id和密码对于用户是不同的,所以我希望将文本字段(用户id和密码)中的值传递给soap消息

如何做到这一点?
提前感谢。

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

对于调用请求,请执行以下操作:

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;
}

希望对您有所帮助。

但是如何将strRequest对象放入soapMessage中。我已经编辑了que。再看一遍,我修改了我的答案。注意这一点。希望这能有所帮助。