Web service recieves null parameters from applicat

2019-07-05 06:06发布

问题:

I've seen topics discussing this but no one has seemed to post a solution. At the moment, I'm testing passing parameters to my .Net web service. When the parameters reach the web service it adds it with an additional string then returns it too my application; but all I'm returning is the string message, not the parameter I passed. Is there something wrong with my web service or my soap method?

Soap:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("A", "workowr");


    SoapSerializationEnvelope envelope =
        new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);    
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
            //SoapObject result = (SoapObject)envelope.getResponse();       
            String resultData = result.toString();
            testTV.setText(resultData);

        }
        catch(Exception e)
        {
            testTV.setText(e.getMessage());
        }

Here is my simple .Net web service:

Public Function getRegInfo(ByVal A As String) As String

Return A + "String message"

End Function

I would appreciate any help.

回答1:

What worked for me was changing the namespace URL in both my .Net webservice and in my application.

For example, I had:

"http://www.example.com/webservices/"

i changed to:

"example.com/webservices/"

and it worked perfectly.

Give it a shot.



回答2:

Yes - there seems to be some problem with having a colon (:) in the webservice namespace, when connecting via KSoap. Regular non-parameter calls work fine, but parameters seem to go through as null for some reason.



回答3:

There is actually no need to have the extra "/" at the end.

After debugging and trying about anything that is written on the net, i found out that the most important thing when passing parameters is to have the same statement in your WebService-declaration and ksoap2.

So use "/" on both places or remove it from both places. the "http://" is also okey to use.



回答4:

The perfect code that adds the parameters this works try this

       SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    envelope.dotNet = true;
    PropertyInfo pi = new PropertyInfo();
    pi.setName("ProcName");
    pi.setValue(a);
    pi.setType(int.class);
    request.addProperty(pi);
    pi=new PropertyInfo();
    pi.setName("UserName");
    pi.setValue(b);
    pi.setType(String.class);
    request.addProperty(pi);

    pi=new PropertyInfo();
    pi.setName("Password");
    pi.setValue(c);
    pi.setType(String.class);
    request.addProperty(pi);

    pi=new PropertyInfo();
    pi.setName("Paras");
    pi.setValue(d);
    pi.setType(String.class);
    request.addProperty(pi);


    Object response = null;

    HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_ADDRESS);

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        response = envelope.getResponse();
    } catch (final Exception e) {
        String error = "no";
    }
    return response.toString();
}


回答5:

You have to copy and past Name Space and soap action exactly the same they appear in WSDL xml file .

I had the same problem and when I removed http:// from (Name Space and Soap Action) the problem was solved.(in the WSDL they are without http://) Actually I tried to access local web service (the service installed in local server )

However I have another application that access an external .NET web service ( central bank web service to get rate exchange ) The WSDL NameSpace and SoapAction Contains http:// My application worked perfectly without removing http://