I am getting bogus data back from my IIS .NET beta 2 WebService. I am using
the Java client below, which calls a method (test_AddThem) to add two
numbers and return the result. This result is always a '0' (zero). I have
another version of this method which adds the xsi:type attribute to each
element in the returned XML, since Microsoft's server does not normally do
this. This method works fine and returns the correct result.
I am adding to the mapping registry the deserializer to deserialize the
'test_AddThemResponse' response element as an Integer yet I still get zero
as the result.
I have been trying to find my bug for about 4 hours now with no luck. Could
someone help me out? I will be very grateful. Thanks.
Peter Roth
Telemetry Technologies Inc.
p: 404.231.0021 ext. 1290
e: [EMAIL PROTECTED]
****************************************************************************
*****
JAVA CLIENT
package com.telemetrytech.utils;
/**
* SoapAddTest.java
* A class to use the SOAP method test_AddThem on the VNOC server
* via Java. This method takes two numbers and returns the result of adding
* the two together.
* @author Peter Roth (c) Telemetry Technologies 2001
*/
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
public class SoapAddTest {
public static void main(String args[]) {
//Read in the arguments to add
if(args.length < 2) {
System.err.println("USAGE java
SoapAddTest firstNum secondNum");
return;
}
Integer firstNum = new Integer (5);
Integer secondNum = new Integer(10);
try {
firstNum = new Integer (args[0]);
secondNum = new Integer(args[1]);
}catch(NumberFormatException e) {
System.out.println("Number Format
Exception\n");
e.printStackTrace();
return;
}
//now lets try and run the method on the server
try {
//the url of the web service
URL url =
new URL
("http://63.75.212.11/VnocngWebService/VnocngWebService.asmx");
Call call = new Call();
//set the unique remote object name
call.setTargetObjectURI("http://telemetrytech.net/VnocngWebService");
//set the method name and encoding
style
call.setMethodName ("test_AddThem");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// Create the type mapping registry
SOAPMappingRegistry smr = new
SOAPMappingRegistry();
IntDeserializer intDeSer= new
IntDeserializer();
// Map the types.
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new
QName("http://telemetrytech.net/VnocngWebServic
"test_AddThemResult"),
null, null,
intDeSer);
call.setSOAPMappingRegistry(smr);
//set up the parameters to the
method
Vector params = new Vector ();
params.addElement (new
Parameter("FirstNum", Integer.class, firstNum, null));
params.addElement (new
Parameter("SecondNum", Integer.class, secondNum, null));
call.setParams (params);
//System.err.println("HEADER:\n\n"+call.getHeader().toString()+"\n");
System.err.println("ENVELOPE:\n\n"+call.buildEnvelope().toString()+"\n");
//connect to the web service and run
the method getting the response back
Response resp =
call.invoke(url,"http://telemetrytech.net/VnocngWebService/test_AddThem" );
if (resp.generatedFault ()) {
Fault fault =
resp.getFault ();
System.out.println
("Ouch, the call failed: ");
System.out.println
(" Fault Code = " + fault.getFaultCode ());
System.out.println
(" Fault String = " + fault.getFaultString ());
} else {
Parameter result =
resp.getReturnValue();
System.out.println("\n"+resp.toString()+"\n");
System.out.println("result of "+ firstNum+ " + "+
secondNum+" = "+ result.getValue().toString() );
}
}catch(MalformedURLException e) {
System.out.println("error in URL
creation.\n"+e.getMessage()+"\n");
e.printStackTrace();
return;
}catch(SOAPException e) {
System.out.println("SOAPException\n");
e.printStackTrace();
return;
}catch(Exception e) {
System.out.println("error in call
creation.\n"+e.getMessage()+"\n");
e.printStackTrace();
return;
}
}
}
END JAVA CLIENT
****************************************************************************
***********