青蛙爱大莹宝
2015-04-02 12:06
采纳率: 100%
浏览 3.3k
已采纳

IOS 调用C#写的Webservice ,传递的参数到Webservice取出的值为NULL

问题描述: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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 青蛙爱大莹宝 2015-04-04 11:55
    已采纳

    问题解决了是拼接的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

    点赞 评论
  • blownewbee 2015-04-02 12:14

    首先检查返回对不对,显然返回了一些东西,如果正确,就是最后对象反序列化的问题了。

    点赞 评论
  • 青蛙爱大莹宝 2015-04-02 12:23

    感谢楼上的回答,您说的反序列化是啥意思呢,麻烦你再指点一下,最好有事例代码。
    一下是我webservice 对应的方法代码
    ///
    /// 删除一条货物信息
    ///
    /// 货物编号
    public string deleteCargoInfo(string cnono)
    {
    try
    {
    if (cnono == null)
    {
    cnono = "16";
    }
    sql = "delete from C where Cno=" + cnono;
    SqlCommand cmd = new SqlCommand(sql, sqlCon);
    cmd.ExecuteNonQuery();
    cmd.Dispose();

                return "1:webservicer return:Sql=" + sql + ",param=" + cnono;
            }
            catch (Exception)
            {
                return "0:webservicer return:Sql=" + sql + ",param=" + cnono;
            }
        }
    
    点赞 评论

相关推荐 更多相似问题