ksoap2 android将自定义对象作为Jax-WS Web方法参数

时间:2015-08-14 09:02:22

标签: java android web-services soap

我正在使用KSOAP2(对我而言比较新)和一个Android客户端来访问我自己设计的soap web服务。到目前为止,我已经能够

  • 接收并处理简单(基元)和自定义对象
  • 将发送原语作为Web方法参数发送。
  • 序列化我的自定义类并构建soap请求。这就是请求的样子:

    <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
        <v:Header />
        <v:Body>
            <n0:insertRequestForApp id="o0" c:root="1" xmlns:n0="http://www.mynamespace.com">
                <arg0 i:type="n0:AppRequest">
                    <reqId i:type="d:int">0</reqId>
                    <parm1Id i:type="d:int">1</parm1Id>
                    <param1UserId i:type="d:int">1</parm1UserId>
                    <param2Id i:type="d:int">1</parm2Id>
                    <param2UserId i:type="d:int">3</parm2UserId>
                    <status i:type="d:int">1</status>
                    <type i:type="d:int">1</type>
                </arg0>
                </n0:insertRequestForApp>
        </v:Body>
    </v:Envelope>
    

我从服务获得的回报是<return>false</return>

这是调用的服务方法

public boolean addRequest(AppRequest req){
    boolean ret = true;
    try {
        PreparedStatement preparedStatement = connection
                .prepareStatement("insert into appointment_requests(status, param1_id, param1_Users_id,"
                        + "param2_id, param2_Users_id, type) values (?, ?, ?, ?, ?, ?)");
        preparedStatement.setInt(1, req.getStatus());
        preparedStatement.setInt(2, req.getParam1tId());
        preparedStatement.setInt(3, req.getParam1UsersId());
        preparedStatement.setInt(4, req.getParam2Id());
        preparedStatement.setInt(5, req.getParam2UsersId());
        preparedStatement.setInt(6, req.getType());
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        ret = false;
        e.printStackTrace();
    }
    return ret;
}`

上面的数据库插入代码已尝试使用普通的Java代码,它可以正常使用Android客户端从服务调用获得的值,但是当从KSoap2调用时服务器日志建议com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails异常。

请帮助任何人?
更新: 我已经在输出中打印了在数据库类中接收的对象,它与发送的对象不同。收到的版本如下所示: Param2 Id: 1 Param2 User Id: 0 *(instead of 3 in the soap message)* Param1 Id: 1 Param1 User Id: 0 *(instead of 1 in the soap message)* Status: 1 Type: 1

在反序列化对象时看起来有问题

0 个答案:

没有答案