You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Jose Soler <js...@com.dtu.dk> on 2003/09/25 15:32:54 UTC

RE: Deserialization problem (SOLVED)

Hi Again,

 thanks guys,I already solved it all. My complx data request/response test is working properly.
 I paste below the final code for the service and the test client as well as the deployment descriptor in case it can be of help for anyone.

Best regards,

jose
------------
Bean Code:
----------------
public class MyStruct {
private String a;
private String b; 

public String geta(){return a;}
public String getb(){return b;}
public void seta(String na){a=na;}
public void setb(String nb){b=nb;}
}
 
--------------------
Service Code
---------------------
public class StructTest2
{
    
    public MyStruct serviceMethod(MyStruct s)
    {
        
        MyStruct auxO=new MyStruct();
        auxO.seta(s.getb());
        auxO.setb(s.geta());
        return auxO;
    }
}
---------------------
Service Deployment Descriptor
-----------------------
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

 <service name="StructTest2" provider="java:RPC">
  <parameter name="className" value="StructTest2"/>
  <parameter name="allowedMethods" value="*"/>
  <beanMapping qname="myNS:MyStruct" 
  	       xmlns:myNS="urn:StructTest2"
  	       languageSpecificType="java:MyStruct"/>
  </service>

</deployment>
-----------------------
Client Code
-----------------------
public class StructTest2Client
{
   public static void main(String [] args) throws Exception {
       
       String target = "http://localhost:8082/axis/services/StructTest2";
       MyStruct request = new MyStruct();
       MyStruct response = new MyStruct();
       //
       request.seta(args[0]);
       request.setb(args[1]);
       //response.seta("j");
       //response.setb("j");
       //
       Service  service = new Service();
       Call     call    = (Call) service.createCall();
       QName 	qn 	= new QName( "urn:StructTest2", "MyStruct");
       //
       String result= "OK: ";
       try
       { 
        call.removeAllParameters();
        call.registerTypeMapping(MyStruct.class, qn, 
       				 new org.apache.axis.encoding.ser.BeanSerializerFactory(MyStruct.class, qn),
       				 new org.apache.axis.encoding.ser.BeanDeserializerFactory(MyStruct.class, qn));                        
        call.setTargetEndpointAddress( new java.net.URL(target) );
        call.setOperationName("serviceMethod");
        call.addParameter( "arg1", qn, ParameterMode.IN );
        call.setReturnType(qn, MyStruct.class);
        //response =  (MyStruct) call.invoke( new Object [] {request});
	java.lang.Object resp =  call.invoke( new Object [] {request});
	response = (MyStruct) resp;
	System.out.println(result + response.geta() + " " + response.getb());
	}catch (AxisFault fault){
		 System.out.println("Error: " + fault.toString());
		}
   }
} 
--------------
SOAP Request in TCP monitor
--------------
POST /axis/services/StructTest2 HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.1 Host: 127.0.0.1 Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 690  <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <serviceMethod soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <arg1 href="#id0"/>
  </serviceMethod>
  <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:MyStruct" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:StructTest2">
   <a xsi:type="xsd:string">a</a>
   <b xsi:type="xsd:string">b</b>
  </multiRef>
 </soapenv:Body>
</soapenv:Envelope>
--------------------
SOAP Response in TCP monitor
-------------------
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Date: Thu, 25 Sep 2003 12:40:21 GMT Server: Apache Coyote/1.0 Connection: close  <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <serviceMethodResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <serviceMethodReturn href="#id0"/>
  </serviceMethodResponse>
  <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:MyStruct" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:StructTest2">
   <a xsi:type="xsd:string">b</a>
   <b xsi:type="xsd:string">a</b>
  </multiRef>
 </soapenv:Body>
</soapenv:Envelope>
-----------------------------