ksoap2 AsyncTask PropertyInfo not recevied to webservice, why?

强颜欢笑 提交于 2019-12-25 06:34:55

问题


I need to send some parameters to my web service and get result. I have used ksoap2-android-assembly-2.4-jar-with-dependencies.jar in lib, my web service work properly :

        [WebMethod]
    public string TestParams(string userName, string password, string startRowIndex, string maximumRows, string OrderType, string IdOpera)
    {
        return userName + " - " + password + " - " + startRowIndex + " - " + maximumRows + " - " + OrderType + " - " + IdOpera;
    }

In main java code :

    private class AsyncCall extends AsyncTask<String, Void, SoapObject > {
    @Override
    protected SoapObject doInBackground(String... params) {

        if (Constants.DEBUG)Log.i(Constants.LOGTAG, "doInBackground");
        AsynGetSellList list = new AsynGetSellList();
        AsynGetSellList.setMAIN_REQUEST_URL(MAIN_REQUEST_URL);
        AsynGetSellList.setMETHOD_NAME(METHOD_NAME);
        AsynGetSellList.setNAMESPACE(NAMESPACE);
        AsynGetSellList.setSOAP_ACTION(SOAP_ACTION);
        javab = list.GetSellList(1);

        return javab;
    }

    @Override
    protected void onPreExecute() {
        if (Constants.DEBUG)Log.i(Constants.LOGTAG, "onPreExecute");
        pDialog = new ProgressDialog(SellList.this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        if (Constants.DEBUG)Log.i(Constants.LOGTAG, "onProgressUpdate");
    }

    @Override
    protected void onPostExecute(SoapObject javab) {
        if (Constants.DEBUG)Log.i(Constants.LOGTAG, "onPostExecute");
        pDialog.dismiss();
        if (isCancelled()) {
            finish();
        }
        if (javab!=null){
            fillSells(javab);
        }
    }
}

and GetSellList.java that include params :

        public SoapObject GetSellList(int startRowIndex) {
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    // افزودن پارامترهای فراخوانی
    request.addProperty("userName", "01395175");
    request.addProperty("password", "123123");
    request.addProperty("startRowIndex", "1");
    request.addProperty("maximumRows", "50");
    request.addProperty("OrderType", "1");
    request.addProperty("IdOpera", "50");

    if (Constants.DEBUG)Log.i(Constants.LOGTAG,"request = "+request);

    //پاکت ساخته شده است
    SoapSerializationEnvelope envelope = getSoapSerializationEnvelope(request);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = getHttpTransportSE(MAIN_REQUEST_URL);

    SoapObject javab = null;
    try {
        if (Constants.DEBUG)Log.i(Constants.LOGTAG,"envelope = "+envelope);
        //فراخوانی وب سرویس با پاکت
        androidHttpTransport.call(SOAP_ACTION, envelope);

        //دریافت پاسخ از وب سرویس           
//      SoapObject result = (SoapObject)envelope.getResponse();
        Object result0 = (Object)envelope.getResponse();
        if (Constants.DEBUG)Log.i(Constants.LOGTAG,"result0 = "+result0);

        SoapObject result = (SoapObject)result0;

        if (Constants.DEBUG)Log.i(Constants.LOGTAG,"result = "+result);

        javab = findTable(result);
    } catch (Exception e) {
        if (Constants.DEBUG)Log.i(Constants.LOGTAG,"Exception = "+e);
        if (Constants.DEBUG)Log.i(Constants.LOGTAG,"Exception = "+e.getMessage());
        e.printStackTrace();
    }
    return javab;
}

other code parts needed :

        public PropertyInfo addParam(String name, Object value) {
        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.name = name;
        propertyInfo.type = value == null ? PropertyInfo.OBJECT_CLASS : value.getClass();
        propertyInfo.setValue(value);
        return propertyInfo;
    }

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

what I see when I check send params in logcat :

TestParams{userName=01395175; password=password; ...}

but the problem : result0 = - - - - - this means (to me) that web service did not receive params. I have tested many way, but do you have enough experience to know what is problem? let me first tell that check web and changed many ways, so if you have seen or faced the same problem, let me know...Thanks.


回答1:


The problem solved, but how? it was due to tempori.org, used as default in my web service. I changed it to my web site url and it solved. It was really really silly error, because in many cases web service reply properly, just when you receive a DataSet, you face an error, not well known. Any way after one day full time try and error it solved.

blogs.msdn.com/b/endpoint/archive/2011/05/12/how-to-eliminate-tempuri-org-from-your-service-wsdl.aspx

How to eliminate tempuri.org from WCF Services WSDL Step 1: Declare a namespace on your service contract

The namespace can be anything. People typically use a URI of some form but it does not have to point to an actual web page. Often people will use a version identifier in the namsepace but there are no rules about what you should do.

// Eliminate tempuri.org from the contract

// If you don't want to us a constant, put the URI here

// [ServiceContract(Namespace = "http://contoso.com/services")]

[ServiceContract(Namespace = Constants.Namespace)]

public interface IService1

{

[OperationContract]

void DoWork();

}

Step 2: Declare a namespace on your service

The service namespace is added with a ServiceBehavior attribute. Using the constant ensures that the namespace is the same for the contract and the service.

// If you don't want to us a constant, put the URI here

// [ServiceBehavior(Namespace = "http://contoso.com/services")]

[ServiceBehavior(Namespace = Constants.Namespace)]

public class Service1 : IService1

{

public void DoWork()

{

}

}

Step 3: Set the binding namespace

<services>

  <service name="EliminateTempUri.Service1">

    <!-- Use a bindingNamespace to eliminate tempuri.org -->

    <endpoint address=""

              binding ="basicHttpBinding" 

              bindingNamespace="http://contoso.com/services"

              contract="EliminateTempUri.IService1"

    />

  </service>

</services>

<behaviors>

  <serviceBehaviors>

    <behavior name="">

      <serviceMetadata httpGetEnabled="true" />

      <serviceDebug includeExceptionDetailInFaults="false" />

    </behavior>

  </serviceBehaviors>

</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />



来源:https://stackoverflow.com/questions/23172937/ksoap2-asynctask-propertyinfo-not-recevied-to-webservice-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!