I can not send values to WebService .NET

-2

This is a simple dollar conversion web service:

public class Callsoap {

    String resultado;
    String erro = null;

public String Call (String ip, String porta, float n){

    String SOAP_ADDRESS = "http://"+ip+":"+porta+"/webservice/WebService.asmx?wsdl";
    String WSDL_TARGET_NAMESPACE = "http://tempuri.org";
    String OPERATION_NAME = "Conversor";
    String SOAP_ACTION = "http://tempuri.org/Conversor";

    int Timeout = 60000;
    HttpTransportSE ht;
    SoapObject request;

    request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
    request.addProperty("n",String.valueOf(n));

    SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);


    ht = new HttpTransportSE(Proxy.NO_PROXY,SOAP_ADDRESS,Timeout);


    try{
        ht.call(SOAP_ACTION,envelope);
        ht.debug = true;
        ht.setXmlVersionTag("<!--?xml version=\"1.0\" encoding= \"UTF-8\" ?-->");

        SoapObject resultadoXML = (SoapObject) envelope.bodyIn;
        SoapPrimitive resultados = (SoapPrimitive) resultadoXML.getProperty("ConversorResult");
        resultado = resultados.toString();
    }catch (Exception e){
        return erro = e.toString();
    }
    request = null;
    ht = null;
    envelope = null;

    return resultado;
}

private final SoapSerializationEnvelope getSoapSerializationEnvelope(SoapObject request) {
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = false;
    envelope.implicitTypes = true;
    envelope.setAddAdornments(false);
    envelope.setOutputSoapObject(request);

    return envelope;
}
}
    
asked by anonymous 20.11.2015 / 01:11

1 answer

0
  • Try to change the line envelope.dotNet = false; to envelope.dotNet = true;
  • Verify that the data type generated in the webService is correct for a correct conversion at the time of returning the data;
  • I use KSoap2 to work with WebServices .NET, which you can also check is the need to register in the SoapSerializationEnvelope object the data type you are using for the return, if the data type is decimal in .NET will probably have to create a Marshal class, as explained below:

    import java.io.IOException;
    
    import org.ksoap2.serialization.Marshal;
    import org.ksoap2.serialization.PropertyInfo;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.xmlpull.v1.XmlPullParser;
    import org.xmlpull.v1.XmlPullParserException;
    import org.xmlpull.v1.XmlSerializer;
    
    public class MarshalDecimal implements Marshal {
    
        public Object readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo propertyInfo)
                throws IOException, XmlPullParserException {
            String stringValue = parser.nextText();
            return new java.math.BigDecimal(stringValue);
        }
    
        public void writeInstance(XmlSerializer writer, Object instance) throws IOException {
            writer.text(instance.toString());
        }
    
        public void register(SoapSerializationEnvelope cm) {
            cm.addMapping(cm.xsd, "decimal", java.math.BigDecimal.class, this);
        }
    }
    

    And in the getSoapSerializationEnvelope() method you will have to add the following statement:

    new MarshalDecimal().register(envelope);
    
        
    20.11.2015 / 11:36