問題描述:IOS 調用C#寫的Webservice ,傳遞的參數到Webservice取出的值為NULL,傳遞前在IOS裡測試能取到值,麻煩用過這塊的幫我看一下,已困擾我兩天 啦~~哈哈
代碼:
NSMutableString *tps=[NSMutableString stringWithString:@""]; //存儲參數名稱
NSMutableString *vps=[NSMutableString stringWithFormat:@""];//存儲參數值
NSMutableString *ts=[NSMutableString stringWithFormat:@""];//組合字符串變量
NSMutableString *mreakString=[NSMutableString stringWithFormat:@""];//組合字符串變量
[mreakString appendString:@"<"];
[mreakString appendString:MethodName]; //方法名
[mreakString appendString:@" xmlns=\"http://tempuri.org/\">"];
//[ParametersKey count]
for (int i = 0; i <[ParametersKey count]; i++)
{
tps = [ParametersKey objectAtIndex:i];
vps = [ParametersValue objectAtIndex:i];
[ts appendString:@"<"];
[ts appendString:@"cnono"];//參數名
[ts appendString:@">"];
[ts appendString:@"17"]; //參數值 (--- 17 傳遞到webservice為NULL值 ----)
[ts appendString:@"</"];
[ts appendString:@"cnono"];
[ts appendString:@">"];
[mreakString appendString:ts];
}
[mreakString appendString:@"</"];
[mreakString appendString:MethodName];
[mreakString appendString:@">"];
NSMutableString *soapMessage2=[NSMutableString stringWithFormat:@""];;
[soapMessage2 appendString:@"</soap:Envelope>"];
生成的協議字符串為:
requestData-----><?xml version="1.0" encoding="utf-8"?>
/soap:Body
/soap:Envelope
<cnono>17</cnono>
/soap:Envelope
服務器返回的串為:
<?xml version="1.0" encoding="utf-8"?>soap:Body1:webservicer return:Sql=delete from C where Cno=,param=/soap:Body/soap:Envelope
問題解決了是拼接的SOAP串的事,按照標准的串拼接後,問題解決。
標准串:
SOAP 1.1
以下是 SOAP 1.2 請求和響應示例。所顯示的占位符需替換為實際值。
POST /StockTest/Service1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/deleteCargoInfo"
<?xml version="1.0" encoding="utf-8"?>
soap:Body
string
/soap:Body
/soap:Envelope