将日期传递给ASMX Web服务(Passing date to ASMX web service)

编程入门 行业动态 更新时间:2024-10-28 15:21:23
日期传递给ASMX Web服务(Passing date to ASMX web service)

我使用asmx web服务在c#over android设备上写。

我建立连接,当在一些web方法中我需要整数或字符串像输入参数,所有工作都很好,但问题是当web方法需要日期时,我尝试以多种格式发送日期但总是有问题得到答案。

我需要发送日期对象,还是喜欢字符串? Web服务查看日期可能与其他内容类似吗?

这是与Web服务“通信”的方法:

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"); } }

当我改变web方法(其中有一些日期工作),我得到日志中的响应)但是当这种方式与日期我只是得到catch(“sss”)在日志中,我调试并发现它刹车:androidHttpTransport。 call(SOAP_ACTION,envelope);

但我在日志中找不到任何关于它的东西,除了我设置的捕获...

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...

最满意答案

对我来说,这看起来像你想要给web服务的dateObj无法解析,这就是为什么在这一行发生异常:

androidHttpTransport.call(SOAP_ACTION, envelope);

但是因为您的格式化程序具有以下格式:

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

也许(三!)“mmm”导致错误? 我很确定这会产生像2月份的“2月”等等......(例如“2014年2月11日”):

尝试以下方法:

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

要么

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

顺便说一句,为了避免本地化和互操作性问题,我经常使用精确格式化为Strings的DateTime对象将这些对象提供给WebService。 因为很多时候我通过例如.asmx Webservice和J2EE Web服务之间的互操作性遇到了问题(例如,对于J2EE和.NET,DateTime的范围不同,如果它是null / nil值,你也会遇到麻烦)。

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).

更多推荐

本文发布于:2023-07-26 03:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270664.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   Web   ASMX   Passing   web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!