CocoNess CocoNess - 28 days ago 10
Java Question

Passing a BigInteger parameter in a Soap Webservice

I'm developing an application on Wildfly 10, JEE. It uses SOAP webservices. I'm thinking of passing in a parameter of type BigInteger. It works OK, but I'm not sure if this is advisable. How is BigInteger represented in the WSDL?

@WebMethod(operationName = "myService")
public myResult myService(
@WebParam(name = "param1") BigInteger param1)
throws ServiceException {

}

Answer

The exception is probably due to the fact that the wrking service uses the xsd:integer type to represent your BigInteger while the other service uses the xsd:int type. One can correctly represent BigIntegers but not the other

The following table gives you the common mappings between java types and their serialized xml version

java types xml serialization

Picture reference: (IBM Knowledge base So as you can see BigInteger should be serialized to xsd:integer. There is another integer type: xsd:int. It is used to represent a signed 32 bits integer, so it does not fit into the range of a BigInteger. On the other hand xsd:integer is a representation of an unbounded integer value, so it will well cover BigInteger.

If you are having these issue you might you an xsd schema to derive your wsdl types from, you can use the following type of reference in your wsdl file: for example in your-wsdl-file.wsdl you can add (right after the tag

<wsdl:types>
    <xsd:schema>
         <xsd:import namespace="http://your/namespace/here" schemaLocation="your-schemafile.xsd"/>
       </xsd:schema>
</wsdl:types>

in your xsd you can use the xsd:integer type to force a right representation of yur BigInteger type.