1 Reply Latest reply on Dec 20, 2004 5:13 AM by Thomas Diesler

    Byte array as a data type

    Mohammad Rahin Newbie

      I need to pass a byte[] as a parameter in one of my Web Services methods as follows,

      public SPDHMessageDTO process(SPDHMessageDTO data);
      

      where SPDHMessageDTO is defined as follows,

      public class SPDHMessageDTO {
      
       // DTO Properties
       private String auditReference;
       private byte[] spdhMessage;
      .....
      }
      


      The web service deploys correctly. The wsdl file generated by wstool is as follows,

      <definitions name="SPDHProtocolService" targetNamespace="http://com.retail_logic.ws/spdhprotocol">
       <types>
       <schema targetNamespace="http://com.retail_logic.ws/spdhprotocol/types">
       <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
       <complexType name="SPDHMessageDTO">
       <sequence>
       <element name="auditReference" type="string"/>
       <element name="spdhMessage" type="base64Binary"/>
       </sequence>
       </complexType>
       </schema>
       </types>
      


      Note that the spdhMessage field is declared as "base64Binary" in the wsdl file.

      The client is written in Java and the client-side stub is again generated by wstool. If I use stub code where the service is located as below everything works just fine.

      private void locateService() {
       spdhService = (SPDHProtocolServiceWS) (new
       SPDHProtocolService_Impl().getSPDHProtocolServiceWSPort());
      }
      


      On the other hand if I use dynamic proxy to locate the service as below I get type mismatch exception on the client side.

      private void locateService(String wsdlURI) throws Exception {
       if (wsdlURI == null || wsdlURI.length() == 0) {
       locateService();
       return;
       }
       ServiceFactoryImpl sf = (ServiceFactoryImpl)
       ServiceFactoryImpl.newInstance();
       URL wsdlURL = new URL(wsdlURI);
       QName qname = new QName(SERVICE_NAMESPACE, SERVICE_NAME);
       Service ots = sf.createService(wsdlURL, qname);
      
       spdhService = (SPDHProtocolServiceWS) ots.getPort(new
       QName(SERVICE_NAMESPACE, SERVICE_PORT),
       SPDHProtocolServiceWS.class);
      }
      
      


      Exception received if dynamic proxy is used:

      Error: deserialization error: unexpected element type: expected={http://www.w3.org/2001/XMLSchema}hexBinary, actual={http://www.w3.org/2001/XMLSchema}base64Binary
      deserialization error: unexpected element type: expected={http://www.w3.org/2001/XMLSchema}hexBinary, actual={http://www.w3.org/2001/XMLSchema}base64Binary
      at com.sun.xml.rpc.encoding.SOAPDeserializationContext.deserializeMultiRefObjects(SOAPDeserializationContext.java:82)
      at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:163)
      at com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:61)
      at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:446)
      at com.sun.xml.rpc.client.dii.CallInvocationHandler.doCall(CallInvocationHandler.java:99)
      at com.sun.xml.rpc.client.dii.CallInvocationHandler.invoke(CallInvocationHandler.java:71)
      at $Proxy0.process(Unknown Source)


      Would very much appreciate if anyone could explain what I need to do to use dynamic proxy at the client-side.

      Thanks.

      - Mohammad Rahin


        • 1. Re: Byte array as a data type
          Thomas Diesler Master

          The standard SAAJ API is agnostic about the J2EE web service deployment model, i.e. it does not know about that jaxrpc-mapping.xml.

          Have a look at
          http://cvs.sourceforge.net/viewcvs.py/jboss/webservice/src/main/org/jboss/webservice/client/ServiceFactoryImpl.java?view=auto

           /**
           * Create a <code>Service</code> instance.
           * <p/>
           * Note, this method is not in the {@link ServiceFactory} interface, it provides the service
           * with additional ws4ee wsdl/java mapping information
           *
           * @param wsdlLocation URL for the WSDL document location
           * @param mappingLocation An optional URL for the jaxrpc-mapping.xml location
           * @param serviceName QName for the service.
           * @param portName An optional port name
           * @return Service.
           * @throws ServiceException If any error in creation of the
           * specified service
           */
           public Service createService(URL wsdlLocation, URL mappingLocation, URL ws4eeMetaData, QName serviceName, String portName) throws ServiceException