douaoren4402
2013-06-24 14:27
浏览 26

从PHP客户端向asp.net webservice发布一个int总是0

Hi I seem have created a SOAP webservice using asp.net , and tested it using an PHP client to get data.And it seems for getting data the service works.

THe problem appears when I try to post the data.It seems that the server always recieve the value 0.Here is my asp.net web service code:

public void DeleteBook(int categoryId)
    {
        using (var conn = new OdbcConnection(connectionString))
        {
            conn.Open();
            using (var command = new OdbcCommand())
            {
                command.Parameters.Add(new OdbcParameter("@CategoryId", categoryId));
                command.CommandText = "DELETE FROM Books WHERE CategoryId = @CategoryId";
                command.ExecuteNonQuery();
            }
        }
    }

And here is my PHP Soap client code:

  $client = new SoapClient($url);
  if(isset($_POST["id"])){
            $id = $_POST["id"];
            echo $id;
            $client->DeleteBook($id);
   }

I debugged the service and it seems the DeleteBook method get's hit but the problem is that the categoryId is 0.

What am I doing wrong?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dssu33392 2013-06-24 15:09
    已采纳

    Hi I managed to solve this problem by actualy sending the parameter as an array.This is what I have done and it worked:

    if(isset($_POST["id"])){
            $id = $_POST["id"];
            $obj = array("categoryId" => $id);
            $client->DeleteBook($obj);
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dru5089 2013-06-24 14:31

    You will need to convert the string to an integer. You can do this either on the client or server side.

    Try writing (int) $id in your PHP code, does this do the trick?

     $client = new SoapClient($url);
      if(isset($_POST["id"])){
            $id = (int) $_POST["id"];
            echo $id;
            $client->DeleteBook($id);
      }
    

    I think that anything that can't be parsed to a integer will be 0.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题