开发者

how to create soap message

I am doing with soap request/response app. I have login page.That have user id and password. This is my soap message.

                         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"
开发者_如何学C                         "</soap:Body>\n"
                         "</soap:Envelope>\n"];    

As user id and password are diff for users, I want to pass the values from the textfields (user id and password) to the soap message.

How to do this? Thanks in advance.


OK So below is some steps to follow. I am not sure exact code you can use or not. But modify it as per your need.

For Calling Request Do something like this :

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 should be like this.

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

Hope this help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜