Hi,
Here's my code, if it is neccessary:
wsdl:
<definitions name="Calculator"
targetNamespace="http://example.com/calculator.wsdl"
xmlns:tns="http://example.com/calculator.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name = "calcRequest">
<part name = "p1" type = "xsd:int">
<part name = "p2" type = "xsd:int">
</message name>
<message name = "calcResponse">
<part name = "p1" type = "xsd:int"/>
</message name>
<portType name = "calculator">
<operation name = "add"/>
<input message = "tns:calcRequest"/>
<output message = "tns:calcResponse"/>
</operation>
<operation name = "subtract"/>
<input message = "tns:calcRequest"/>
<output message = "tns:calcResponse"/>
</operation>
</portType>
<binding name="CalculatorSoapBinding"
type="tns:calculator">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="add">
<soap:operation
soapAction="http://example.com/calculator/add"
style="document" />
<input name="addRequest">
<soap:body use="literal"
namespace="http://example.com/calculator.wsdl" />
</input>
<output name="addResponse">
<soap:body use="literal"
namespace="http://example.com/calculator.wsdl" />
</output>
</wsdl:operation>
<operation name="subtract">
<soap:operation
soapAction="http://example.com/calculator/subtract"
style="document" />
<input name="subtractRequest">
<soap:body use="literal"
namespace="http://example.com/calculator.wsdl" />
</input>
<output name="subtractResponse">
<soap:body use="literal"
namespace="http://example.com/calculator.wsdl" />
</output>
</operation>
</binding>
</definitions>
This is the code to the CalcClient.java:
package onjava;
import java.io.*;
import java.net.*;
import java.util.*;
import java.lang.Integer.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
public class CalcClient {
public static void main(String[] args) throws Exception {
URL url = new
URL("http://150.132.6.129:8080/soap/servlet/rpcrouter");
Integer p1 = new Integer(args[0]);
Integer p2 = new Integer(args[1]);
Integer p3 = new Integer(args[2]);
System.out.println("3:e parametern = " + p3 );
System.out.println("3:e parametern intValue = " + p3.intValue() );
int pm = 0;
pm = p3.intValue();
// Build the call.
Call call = new Call();
call.setTargetObjectURI("urn:onjavaserver");
if( pm == 1 )
{
System.out.println( "Inne i if 1 " );
call.setMethodName("add");
}
if( pm == 2 )
{
System.out.println( "Inne i if 2 " );
call.setMethodName("subtract");
}
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector();
params.addElement(new Parameter("p1", Integer.class, p1, null));
params.addElement(new Parameter("p2", Integer.class, p2, null));
call.setParams (params);
// make the call: note that the action URI is empty because the
// XML-SOAP rpc router does not need this. This may change in the
// future.
Response resp = call.invoke(url, "" );
// Check the response.
if ( resp.generatedFault() ) {
Fault fault = resp.getFault ();
System.out.println("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(result.getValue());
}
}
}
Here's the code to the CalcService.java:
package onjava;
public class CalcService {
public int add(int p1, int p2) {
return p1 + p2;
}
public int subtract(int p1, int p2) {
return p1 - p2;
}
}
Best regards,
Rebecca