使用KSoap从android代码传递给asmx服务的参数在服务定义时变为null(在.Net Side)

时间:2014-05-30 12:54:23

标签: android .net asmx ksoap

我使用kso​​ap库从android调用asmx服务我也将一些参数传递给该服务,但我得到所有参数EMPTY(即"")in服务定义。如果我在调用asmx服务之前在我的android代码中打印请求对象,它会显示正确的值,但在服务定义中获取空参数。

    ***My Android code is--***

public final String WSDL_TARGET_NAMESPACE = "http://www.example.com/abc/";
public final String SOAP_ADDRESS = "http://www.example.com/abc/WS.asmx";

public final String TEST_OPERATION="ServiceName";
public final String TEST_SOAP_ACTION="http://www.example.com/abc/ServiceName";  

public String ServiceName(String strParam1, String strParam2)
{
    ***// following Log printing correct value***
    Log.w("*******", "strParam1= "+strParam1+", strParam2= "+strParam2);

    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,TEST_OPERATION);
    PropertyInfo pi=new PropertyInfo();
    pi.setName("strParam1");
    pi.setValue(strParam1);
    pi.setType(String.class);
    request.addProperty(pi);

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

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;

    ***// Following statement printing correct value***     
    Log.w("request= ", request.toString());
    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
    Object response=null;
    try
    {
        httpTransport.call(TEST_SOAP_ACTION, envelope);
        response = envelope.getResponse();
    }
    catch (Exception exception)
    {
        response=exception.toString();
    }
    return response.toString();
}

我的.Net代码(即服务定义)是---

    [WebMethod]
     public String ServiceName(string strParam1, string strParam2)
     {
         try
         {
             string Con = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
             SqlConnection sn = new SqlConnection(Con);
             if (sn.State == ConnectionState.Open)
                 sn.Close();
             sn.Open();
             SqlTransaction trans = sn.BeginTransaction();

             try
             {
                 ***// Following statement inserting EMPTY value in to the database***
                 Generic.db.DepositTransaction_insert(strParam1, strParam2, "INSERT");

                 return "Record Save Successfully";
             }

             catch (Exception ex)
             {

                 return ex.ToString();
             }
         }

    catch (Exception ex)
        {
                 return ex.ToString();
        }
}

希望你明白我想说的话......!请帮忙......谢谢..!

1 个答案:

答案 0 :(得分:0)

最后我得到了答案。这只是一个拼写错误。查看我的Android代码的前4行

public final String WSDL_TARGET_NAMESPACE = "http://www.example.com/abc/";
public final String SOAP_ADDRESS = "http://www.example.com/abc/WS.asmx";

public final String TEST_OPERATION="ServiceName";
public final String TEST_SOAP_ACTION="http://www.example.com/abc/ServiceName";

它包含字符串 www.example.com 应该是www.Example.com (它区分大小写)