XML & Web services: How Can I Handle a Microsoft "char" wsdl type from Axis client

  1. I am trying to consume a web service written in .NET. When I generate the client using Apache Axis, most of the methods work. However, in the WSDL for the web service I am trying to consume some elements are defined as a char data type: For some reason Apache axis trys to map this char datatype to an "UnsignedShort". So when the soap envelope is sent to the .NET service it contains: 1 instead of something like: 1 (where namespace q0="http://microsoft.com/wsdl/types/") The causes the web service to fail. How can I configure Apache Axis so that the client will send the Microsoft char type in the soap envelope: 1
  2. The character in .NET is converted into an unsignedShort that takes the value for 0 - 255. Its the unicode representation of the character. In Java while you are populating the value just typecast an character to int. Say I need to pass a 'S' to the element, I just need to do (int)'S' and set the value. Sash http://tech-sash.blogspot.com
  3. Solution[ Go to top ]

    I had to revisit this again from the last time I posted the question. Thought I would post this in case anyone else has this problem. With Axis1 I had to create a new object with a customer serializer and deserializer. Here is the New Object: public class MicrosoftChar { private String value; public MicrosoftChar(String value) { super(); this.value = value; } public MicrosoftChar(int value) { super(); this.value = String.valueOf(value); } public MicrosoftChar(char value) { super(); this.value = String.valueOf((int)value); } public String toString() { //return getStringVal("", this); return value; } /** * @return the value */ public String getValue() { return value; } /** * @param value the value to set */ public void setValue(String value) { this.value = value; } } Here is the serializer: public class MicrosoftCharSerializer implements Serializer { private static final long serialVersionUID = 4981133577902775230L; public static final QName myTypeQName = new QName("typeNS", "Data"); /** SERIALIZER STUFF */ /** * Serialize an element named name, with the indicated attributes * and value. * @param name is the element name * @param attributes are the attributes...serialize is free to add more. * @param value is the value * @param context is the SerializationContext */ public void serialize(QName name, Attributes attributes, Object value, SerializationContext context) throws IOException { if (!(value instanceof MicrosoftChar)) throw new IOException("Can't serialize a " + value.getClass().getName() + " with a DataSerializer."); MicrosoftChar data = (MicrosoftChar)value; context.setWriteXMLType(new QName("http://microsoft.com/wsdl/types/","char")); context.startElement(name, attributes); context.writeString(data.getValue()); context.endElement(); } public String getMechanismType() { return Constants.AXIS_SAX; } public Element writeSchema(Class javaType, Types types) throws Exception { return null; } } Then from the SoapStub I had to register this new type with the call: _call.registerTypeMapping(MicrosoftChar.class, new QName("http://samples.data", "Data"), MicrosoftCharSerializerFactory.class, MicrosoftCharDeserializerFactory.class); Once I did this in correctly included the Microsoft:char and namespace to the soap request: 0 Look at the Axis 1 sample/encoding example for more info.