Question

I use asmx web service writes in c# over android device.

I make connection and when in some web method I need integer or string like input param,all work great, but problem is when web method need date, I try to send date in many format but always I have problem to get answer.

I need to send date object, or like string? It is possible that web service view date like something else?

This is method for "communication" with web service:

public void connectSOAP() 
{
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    String dateStr = "04/05/2010"; 
    Date dateObj=null;
    SimpleDateFormat curFormater = new SimpleDateFormat("dd/mmm/yyyy"); 
    try 
    {
        dateObj = curFormater.parse(dateStr);
    } 
    catch (java.text.ParseException e1) 
    {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } 
    request.addProperty("dtFrom",dateObj);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.setOutputSoapObject(request);
    envelope.dotNet = true;
    try 
    {
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
        if (envelope.getResponse() != null) 
        {
            if (envelope.bodyIn instanceof SoapFault) 
            {
                String str = ((SoapFault) envelope.bodyIn).faultstring;
                Log.i("", str);
            } 
            else 
            {
                SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                Log.d("WS", String.valueOf(resultsRequestSOAP));
            }    
        };
    } 
    catch (Exception e) 
    {
        Log.d("WS","sss");
    }
}

When i change web method(something with out date it work),I get response in log) But when is this way with date i just get catch ("sss" ) in log,i debug and find that it brake on: androidHttpTransport.call(SOAP_ACTION, envelope);

But i not find anything about that in log except catch that i set...

Was it helpful?

Solution

For me this looks like the dateObj which you want to give to the webservice can not be parsed, thats why the exception occurre at this line:

androidHttpTransport.call(SOAP_ACTION, envelope);

But as your formatter has this format:

SimpleDateFormat curFormater = new SimpleDateFormat("dd/mmm/yyyy"); 

Maybe the (three!)"mmm" are causing the error?? I am pretty sure this will produce something like e.g. "Feb" for February and so on.. (e.g. "11/Feb/2014"):

Try something like:

SimpleDateFormat curFormater = new SimpleDateFormat("dd/mm/yyyy"); 

or

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy"); 

Btw, to avoid localisation and interoperability issues, i often use DateTime objects accurately formatted to Strings for giving that objects over to WebService. Because many times i had problems by interoperability between e.g. .asmx Webservice and J2EE web service (e.g. the range of DateTime is not the same for J2EE and .NET and if it's a null/nil value you also run in troubles).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top