Re: Client with parameter can`t comunicate with Web Servic e
"Fournier, Andrew" <[email protected]> Tue, 13 Apr 2004 16:31:14 -0400
| Newsgroups | gmane.comp.windows.devel.soap.general |
|---|---|
| Message-ID | <[email protected]> |
I noticed that your client uses the parameter names "NumberOne" and "NumberTwo" (note the upper case 'N') while the .NET Web Method = signature uses "numberOne" and "numberTwo" (with a lowercase 'n'). I believe the = .NET serialization/deserialization code uses the parameter names as they = appear in your code to determine how to deserialize a SOAP message. If they = don't match exactly, then incoming SOAP messages will not be deserialized correctly. -----Original Message----- From: Discussion of implementing SOAP applications today [mailto:[email protected]] On Behalf Of L=E1zara Camila Generoso = de Moraes Sent: Tuesday, April 13, 2004 4:07 PM To: [email protected] Subject: [SOAP] Client with parameter can`t comunicate with Web Service 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, 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 The contents of this e-mail are intended for the named addressee only. = It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or = disclose it to anyone else. If you received it in error please notify us = immediately and then destroy it.=20