简体   繁体   English

类型中的整数字段不解析java Web服务中的请求参数

[英]Integer field in a type does not parse request parameter in java web service

Why does Integer field couldn't get the value that i sent. 为什么Integer字段无法获取我发送的值。 If i use Integer parameter by itself (like sending an ID) in WebMethod works fine. 如果我在WebMethod中使用Integer参数(比如发送ID)可以正常工作。

Also the String field can get the value that i sent without any problem. String字段也可以获得我发送的值而没有任何问题。

Here is the web service: 这是Web服务:

@WebService(serviceName = "testWS")
public class testWS {

    @WebMethod(operationName = "Hello")
    public Integer Hello(@WebParam(name = "testData") TEST testData) {
            return testData.getINTPROP();
    }
}

TEST type definition: TEST类型定义:

@XmlAccessorType(XmlAccessType.FIELD)
public class TEST {

    private Integer INTPROP;//making public also didn't work

    public Integer getINTPROP() {
        return INTPROP;
    }

    public void setINTPROP(Integer INTPROP) {
        this.INTPROP = INTPROP;
    }

    private String STRINGPROP;

    public String getSTRINGPROP() {
        return STRINGPROP;
    }

    public void setSTRINGPROP(String STRINGPROP) {
        this.STRINGPROP = STRINGPROP;
    }
}

C# consumer application: C#消费者应用:

...
test f = new test();

f.INTPROP = 123;
f.STRINGPROP = "abcdef";

var ff = ws.Hello(f);//returns 0

I hope i could explained my problem. 我希望我能解释我的问题。 thanks. 谢谢。

Try to change the setter to String. 尝试将setter更改为String。

public void setINTPROP(String INTPROP) { this.INTPROPString = INTPROP; public void setINTPROP(String INTPROP){this.INTPROPString = INTPROP;

Then change the String to an integrer with another function. 然后使用另一个函数将String更改为integrer。 Return it as an integer, this should solve the problem. 将其作为整数返回,这应该可以解决问题。

Here is another aproach: 这是另一个方法:

Add this function. 添加此功能。 Java should be able to handle this. Java应该能够处理这个问题。

If the Variable you are passing is a integer, then the function you have will be used. 如果要传递的变量是整数,则将使用您拥有的函数。 If it is a String, Then this function will be called: 如果它是一个String,那么将调用此函数:

public String setINTPROP(String INTPROP) {
    this.INTPROP = Integer.valueOf(INTPROP);

Ok. 好。 Marking field with @XmlSchemaType solved my problem. 使用@XmlSchemaType标记字段解决了我的问题。

@XmlSchemaType(name = "string")
public Integer INTPROP

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

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