Client with parameter can`t comunicate with Web Service
Lázara Camila Generoso de Moraes <[email protected]> Tue, 13 Apr 2004 17:06:47 -0300
| Newsgroups | gmane.comp.windows.devel.soap.general |
|---|---|
| Message-ID | <C2D2C8DFFB65D641AAB4BD56A4F9A0439B0653@ipe-div-mail.eldorado.org.br> |
Hi everyone,
We are developing a projet that envolves a Java application acessing
.Net web services remotly.=20
Currently this application comunicates to a server that uses Java
tecnology and comunicate themselves using RMI. But we wish to convert =
this
server from Java to .net,=20
besides the client application must be in Java.=20
To learn how to do this, we create a simple application. We have a
client that must send 2 parameters to a .NET WebService. These =
parameters
will be added and returned to the client.=20
But that Web Service is not receiving the parameters correctly and
always return 0, as a result.
I`m sending the clients` code and the Web Services` code.
It seems that the parameters are being encoded by the client
application and not correctly unmarshalled on server side, how can we =
solve
this?
Thanks a lot
L=E1zara Camila
=09
CLIENTS`CODE
import org.apache.soap.encoding.soapenc.BeanSerializer;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.util.xml.QName;
import java.net.URL;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import java.util.Vector;
import java.lang.Double;
import java.util.Properties;
import org.apache.soap.transport.http.SOAPHTTPConnection;
public class testClient {
public static void main(String[] args) throws Exception {
URL url =3D new URL
("http://localhost/Teste/WebServices/Service1.asmx");
=09
SOAPMappingRegistry smr =3D new SOAPMappingRegistry ();
=09
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new
QName("http://schemas.xmlsoap.org/soap/encoding/","double"),java.lang.Do=
uble
.class, null, new
org.apache.soap.encoding.soapenc.DoubleObjectDeserializer());
=09
// StringDeserializer sd =3D new StringDeserializer ();
// ParameterSerializer ps=3D new ParameterSerializer ();
// smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName ("",
"Result"), null, null, sd);
// create the transport and set parameters
SOAPHTTPConnection st =3D new SOAPHTTPConnection();
// build the call.
Call call =3D new Call ();
call.setSOAPTransport(st);
call.setSOAPMappingRegistry (smr);
call.setTargetObjectURI
("http://www.catalin.com/webservices/");
=09
call.setMethodName("addNumbers");
call.setEncodingStyleURI (Constants.NS_URI_SOAP_ENC);
=09
Vector params =3D new Vector();
params.addElement(new Parameter("NumberOne", Integer.class,
new Integer(1),null ));
params.addElement(new Parameter("NumberTwo", Integer.class,
new Integer(2),null ));
=09
call.setParams(params);
call.setSOAPMappingRegistry(smr);
=09
Response resp =3D null;
try {
System.out.println( "dentro do try do invoke ");
resp =3D call.invoke (url,
"http://www.catalin.com/webservices/addNumbers");=09
=09
}
catch (SOAPException e) {
=09
System.err.println("Caught SOAPException (" +
e.getFaultCode () + "): " + e.getMessage ());
return;
}
// check response
if (resp !=3D null && !resp.generatedFault()) {
Parameter ret =3D resp.getReturnValue();
Object value =3D ret.getValue();
=09
}
else {
Fault fault =3D resp.getFault ();
System.err.println ("Generated fault: ");
System.out.println (" Fault Code =3D " +
fault.getFaultCode());
System.out.println (" Fault String =3D " +
fault.getFaultString());
}
}
}
=09
WEB SERVICES` CODE
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace Teste.WebServices
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web
Services Designer
InitializeComponent();
}
#region Component Designer generated code
=09
//Required by the Web Services Designer=20
private IContainer components =3D null;
=09
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components !=3D null)
{
components.Dispose();
}
base.Dispose(disposing); =09
}
=09
#endregion
[WebMethod]
=09
[System.Web.Services.Protocols.SoapRpcMethodAttribute(
"http://www.catalin.com/webservices/addNumbers",
=09
RequestNamespace=3D"http://www.catalin.com/webservices/"),=20
=09
ResponseNamespace=3D"http://www.catalin.com/webservices/")]
public double addNumbers(int numberOne, int numberTwo)=20
{
return numberOne + numberTwo;
}
}
}
=09
=20