请帮忙.
我在Eclipse中的Logcat
12-19 15:58:11.951: W/dalvikvm(2041): threadID=1: thread exiting with uncaught exception (group=0x4001d800)12-19 15:58:11.961: E/AndroIDRuntime(2041): FATAL EXCEPTION: main12-19 15:58:11.961: E/AndroIDRuntime(2041): java.lang.RuntimeException: double ID12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.read(SoapSerializationEnvelope.java:407)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.readUnkNown(SoapSerializationEnvelope.java:273)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.readUnkNown(SoapSerializationEnvelope.java:273)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.readUnkNown(SoapSerializationEnvelope.java:273)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.serialization.soapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:151)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.soapEnvelope.parse(SoapEnvelope.java:140)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.transport.Transport.parseResponse(Transport.java:116)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.transport.httpTransportSE.call(httpTransportSE.java:259)12-19 15:58:11.961: E/AndroIDRuntime(2041): at org.ksoap2.transport.httpTransportSE.call(httpTransportSE.java:114)12-19 15:58:11.961: E/AndroIDRuntime(2041): at com.example.webservicee.MainActivity.onClick(MainActivity.java:133)12-19 15:58:11.961: E/AndroIDRuntime(2041): at androID.vIEw.VIEw.performClick(VIEw.java:2408)12-19 15:58:11.961: E/AndroIDRuntime(2041): at androID.vIEw.VIEw$PerformClick.run(VIEw.java:8816)12-19 15:58:11.961: E/AndroIDRuntime(2041): at androID.os.Handler.handleCallback(Handler.java:587)12-19 15:58:11.961: E/AndroIDRuntime(2041): at androID.os.Handler.dispatchMessage(Handler.java:92)12-19 15:58:11.961: E/AndroIDRuntime(2041): at androID.os.Looper.loop(Looper.java:123)12-19 15:58:11.961: E/AndroIDRuntime(2041): at androID.app.ActivityThread.main(ActivityThread.java:4627)12-19 15:58:11.961: E/AndroIDRuntime(2041): at java.lang.reflect.Method.invokeNative(Native Method)12-19 15:58:11.961: E/AndroIDRuntime(2041): at java.lang.reflect.Method.invoke(Method.java:521)12-19 15:58:11.961: E/AndroIDRuntime(2041): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)12-19 15:58:11.961: E/AndroIDRuntime(2041): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:626)
MainActivity.java
package com.example.webservicee; import java.io.IOException;import org.ksoap2.soapEnvelope;import org.ksoap2.soapFault;import org.ksoap2.serialization.PropertyInfo;import org.ksoap2.serialization.soapObject;import org.ksoap2.serialization.soapPrimitive;import org.ksoap2.serialization.soapSerializationEnvelope;import org.ksoap2.transport.httpTransportSE;import org.xmlpull.v1.XmlPullParserException;import androID.os.Bundle;import androID.app.Activity;import androID.util.Log;import androID.vIEw.Menu;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.TextVIEw;public class MainActivity extends Activity { final static String nameSPACE = "http://tempuri.org/"; final static String METHOD_name = "GetContent"; final static String SOAP_ACTION = "http://tempuri.org/GetContent"; final static String URL = "http://www.example.com/XMLGenerator/GenerateXML.asmx"; private button Mybtn; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); deger = (EditText) findVIEwByID(R.ID.deger); sonuc = (TextVIEw) findVIEwByID(R.ID.flag); Mybtn = (button) findVIEwByID(R.ID.hesapla); Mybtn.setonClickListener(new OnClickListener() { public voID onClick(VIEw v) { // Todo auto-generated method stub SoapObject Request = new SoapObject(nameSPACE,METHOD_name); //My webservice paramaters Request.addProperty("SectionsInclude","10"); Request.addProperty("documentCount",10); Request.addProperty("SortBy","0"); Request.addProperty("SortOrder","ASC"); Request.addProperty("Username","myuser"); Request.addProperty("Pass","Lsss"); /**/ /* PropertyInfo pi=new PropertyInfo(); pi.setname("arg0"); pi.setValue("10"); pi.setType(String.class); Request.addProperty(pi); pi=new PropertyInfo(); pi.setname("arg1"); pi.setValue(10); pi.setType(Integer.class); Request.addProperty(pi); pi=new PropertyInfo(); pi.setname("arg2"); pi.setValue("0"); pi.setType(String.class); Request.addProperty(pi); pi=new PropertyInfo(); pi.setname("arg3"); pi.setValue("ASC"); pi.setType(String.class); Request.addProperty(pi); pi=new PropertyInfo(); pi.setname("arg4"); pi.setValue("myuser"); pi.setType(String.class); Request.addProperty(pi); pi=new PropertyInfo(); pi.setname("arg5"); pi.setValue("Lsss"); pi.setType(String.class); Request.addProperty(pi); */ SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); soapEnvelope.dotNet = true; soapEnvelope.setoutputSoapObject(Request); //soapEnvelope.bodyOut = Request; httpTransportSE aht = new httpTransportSE(URL); try { aht.call(SOAP_ACTION,soapEnvelope); } catch (IOException e) { // Todo auto-generated catch block e.printstacktrace(); } catch (XmlPullParserException e) { // Todo auto-generated catch block e.printstacktrace(); } String result; try { result = "Fahrenheit:"+(SoapPrimitive) soapEnvelope.getResponse(); Log.d("--Result-- ",result); //sonuc.setText(result); } catch (SoapFault e) { e.printstacktrace(); } } }); } @OverrIDe public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main,menu); return true; }}
这是示例响应xml:
<?xml version="1.0" enCoding="utf-8"?><Liste><document ID="6" Titles="bestPeople" showingDate="27.09.2011 00:00:00" date="27.09.2011 00:00:00" ContentID=rbHe8zKvDTG7TLS" ><part ID="6" baslik="best" icerik="<table style="wIDth: 188px; height: 24px;" border="tbody>
</table>" resim=""><SecNotes><![cdaTA[]]></SecNotes><ContNotes><![cdaTA[]]></ContNotes></part><SecNotes><![cdaTA[]]></SecNotes><ContNotes><![cdaTA[]]></ContNotes></document></Liste>解决方法 我解决了我添加了这段代码.它正在工作.
我的代码
@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); init();}private voID init(){ //your webservice envelope String envelope="<?xml version=\"1.0\" enCoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetContentTreeBySections xmlns=\"http://tempuri.org/\"><SectionsInclude>%s</SectionsInclude><documentCount>%s</documentCount><SortBy>%s</SortBy><SortOrder>%s</SortOrder><Username>%s</Username><Pass>%s</Pass></GetContentTreeBySections></soap:Body></soap:Envelope>"; String myEnvelope = String.format(envelope,"myParam1 value","myParam2 value","myParam3 value","myParam4 value"); String url = "http://www.mywebserice.com/XMLGenerator/GenerateXML.asmx"; String soapAction = "http://tempuri.org/GetContentTreeBySections"; String response = CallWebService(url,soapAction,myEnvelope); //Log.v("response",response); Toast.makeText(getApplicationContext(),"this"+response,Toast.LENGTH_LONG).show(); String xml=response; }@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main,menu); return true;}String CallWebService(String url,String soapAction,String envelope) { final DefaulthttpClIEnt httpClIEnt=new DefaulthttpClIEnt(); // request parameters httpParams params = httpClIEnt.getParams(); httpconnectionParams.setConnectionTimeout(params,10000); httpconnectionParams.setSoTimeout(params,15000); // set parameter httpProtocolParams.setUseExpectContinue(httpClIEnt.getParams(),true); // POST the envelope httpPost httppost = new httpPost(url); // add headers httppost.setheader("soapaction",soapAction); httppost.setheader("Content-Type","text/xml; charset=utf-8"); String responseString=""; try { // the entity holds the request httpentity entity = new StringEntity(envelope); httppost.setEntity(entity); // Response handler ResponseHandler<String> rh=new ResponseHandler<String>() { // invoked when clIEnt receives response public String handleResponse(httpResponse response) throws ClIEntProtocolException,IOException { // get response entity httpentity entity = response.getEntity(); // read the response as byte array StringBuffer out = new StringBuffer(); byte[] b = EntityUtils.toByteArray(entity); // write the response byte array to a string buffer out.append(new String(b,b.length)); return out.toString(); } }; responseString=httpClIEnt.execute(httppost,rh); } catch (Exception e) { Log.v("exception",e.toString()); } // close the connection httpClIEnt.getConnectionManager().shutdown(); return responseString;}总结
以上是内存溢出为你收集整理的在Android中调用.NET Web服务全部内容,希望文章能够帮你解决在Android中调用.NET Web服务所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)