简体   繁体   English

从PHP客户端向int.net网络服务发布int始终为0

[英]Post an int from a PHP client to a asp.net webservice is always 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. 嗨,我似乎已经使用asp.net创建了一个SOAP Web服务,并使用PHP客户端对其进行了测试以获取数据,并且该服务似乎可以获取数据。

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: 当我尝试发布数据时出现问题。服务器似乎总是接收值0。这是我的asp.net Web服务代码:

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: 这是我的PHP Soap客户端代码:

  $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. 我调试了服务,似乎DeleteBook方法获得成功,但问题是categoryId为0。

What am I doing wrong? 我究竟做错了什么?

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);
}

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? 尝试在您的PHP代码中编写(int) $id ,这样做有用吗?

 $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. 我认为任何无法解析为整数的值都将为0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM