我在肥皂请求中发送数据数组时遇到问题。
使用以下代码,我可以得到以下回复。
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/\" xmlns=\"http://xmlns.oracle.com/Enterprise/Tools/services/TEST_SRVC\">\n"
"<soap:Body>\n"
"<TEST_SRVC_OP/>\n"
"<OPRID>%@</OPRID>\n"
"<PWD>%@</PWD>\n"
"<REQUEST_ID>%@</REQUEST_ID>\n"
"<PORT_CD>%@</PORT_CD>\n"
"<SIZE_CD>%@</SIZE_CD>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",strUserName,strPassword,strRequestID,strSize] ;
生成的肥皂消息:
<?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/" xmlns="http://xmlns.oracle.com/Enterprise/Tools/services/TEST_SRVC">
<soap:Body>
<TEST_SRVC_OP/>
<OPRID> username </OPRID>
<PWD> passowrd </PWD>
<REQUEST_ID> R123 </REQUEST_ID>
<PORT_CD> TEST1 </PORT_CD>
<SIZE_CD>40</SIZE_CD>
</soap:Body>
</soap:Envelope>
但是,我需要生成这样的肥皂信息。
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://xmlns.oracle.com/Enterprise/Tools/services/TEST_SRVC" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<TEST_SRVC_OP />
<OPRID>username</OPRID>
<PWD>passowrd</PWD>
<REQUEST_ID>R123</REQUEST_ID>
<Detailrow>
<PORT_CD>TEST1</PORT_CD>
<SIZE_CD>40</SIZE_CD>
</Detailrow>
<Detailrow>
<PORT_CD>TEST2</PORT_CD>
<SIZE_CD>60</SIZE_CD>
</Detailrow>
</soap:Body>
</soap:Envelope>
答案 0 :(得分:0)
strSoapMsg = [[NSString alloc] initWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
"<soap12:Body>"
"<GetPortfolioList xmlns=\"http://tempuri.org/\">"
"<EmailID>%@</EmailID>"
"<Password>%@</Password>"
"<TradingGameID>%d</TradingGameID>"
"</GetPortfolioList>"
"</soap12:Body>"
"</soap12:Envelope>",gameUserName,gamePassword,gameid];
//---print it to the Debugger Console for verification---
NSLog(@"soapMsg..........%@",strSoapMsg);
NSURL *url = [NSURL URLWithString:@"http://www.abc.sirus/Process/process.asmx"];
req = [NSMutableURLRequest requestWithURL:url];
//---set the headers---
NSString *msgLength = [NSString stringWithFormat:@"%d",[strSoapMsg length]];
[req addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/GetPortfolioList" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
//---set the HTTP method and body---
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [strSoapMsg dataUsingEncoding:NSUTF8StringEncoding]];
// [activityIndicator startAnimating];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webPortFolio = [[NSMutableData data] retain];
}
答案 1 :(得分:0)
如果data
PORT_CD
和SIZE_CD
为create
,或者不是NSString *strUserName =@"username";
NSString *strPassword =@"password";
NSString *strRequestID =@"R123";
//Here all port_cd with size_cd here
NSArray *arrData = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"TEST1",@"portcd",@"50",@"sizecd",nil],[NSDictionary dictionaryWithObjectsAndKeys:@"TEST2",@"portcd",@"60",@"sizecd",nil],[NSDictionary dictionaryWithObjectsAndKeys:@"TEST3",@"portcd",@"70",@"sizecd",nil],nil];
//create 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/\" xmlns=\"http://xmlns.oracle.com/Enterprise/Tools/services/TEST_SRVC\">\n"
"<soap:Body>\n"
"<TEST_SRVC_OP/>\n"
"<OPRID>%@</OPRID>\n"
"<PWD>%@</PWD>\n"
"<REQUEST_ID>%@</REQUEST_ID>\n",strUserName,strPassword,strRequestID];
//Append port_cd and size_cd here to soap message
for (NSDictionary *dictData in arrData)
{
NSString *strPortCD = [dictData objectForKey:@"portcd"];
NSString *strSizeCD = [dictData objectForKey:@"sizecd"];
soapMessage = [soapMessage stringByAppendingString:[NSString stringWithFormat:@"<Detailrow>\n<PORT_CD>%@</PORT_CD>\n<SIZE_CD>%@</SIZE_CD>\n</Detailrow>\n",strPortCD,strSizeCD]];
}
soapMessage = [soapMessage stringByAppendingString:@"</soap:Body>\n</soap:Envelope>"];
NSLog(@"soapMessage : %@",soapMessage);
,请参阅以下示例:
{{1}}