I cannot send values to Webservice . NET

Asked

Viewed 83 times

-2

This is a simple dollar conversion webservice:

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;
}
}
  • 2

    Give more information about the problem. This code is not C#.

  • This is an Android app and send a variable to multiply within the webservice and back a number. But always returns 0

  • So this isn’t C, right?

  • Yes right! is Android trying to connect on a Webservice . net

  • Edith your question, make the necessary changes to the tags and also add more information to better build your question. I when I formatted the question code also added the tag C# depending on the information of the title, as I do not notice anything of both languages, but you should edit it and add/remove tags depending on your snap context.

  • Webssrvice is running in debug or you published it?

  • I posted it on the local IIS

Show 2 more comments

1 answer

0

  1. Try to change the line envelope.dotNet = false; for envelope.dotNet = true;
  2. Check that the data type generated in the webservice is correct for a correct conversion when bringing the return data;

I use Ksoap2 to work with Webservices . NET, which you can also check is about the need to register on the object SoapSerializationEnvelope the type of data you are using for the return, if the data type is decimal in . NET you will probably have to create a class of Marshal, as set out 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 method getSoapSerializationEnvelope() you will need to add the following instruction:

new MarshalDecimal().register(envelope);
  • I switched to test true for false... But MSM so does not work!

  • The function returns string... And takes strings but always returns zero is not arriving until wbeservice values

  • @Silaspsilva, I suggest you look for a tool like Wsdl2ksoap2 to convert your webservice to Android and based on the generated code, Voce can find the source of your problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.