WSUtils类代码:
- Java code
package com.dai.hellows; import java.io.IOException; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.MarshalBase64; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import org.xmlpull.v1.XmlPullParserException; public class WSUtils { public static String getMessage(){ String message=""; //命名空间 String namespace="http://tempuri.org/"; //请求URL String serviceURL="http://www.zhichengtz.com/WebService.asmx"; //要调用的方法名 String methodName="HelloWorld"; SoapObject request=new SoapObject(namespace,methodName); SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut=request; (new MarshalBase64()).register(envelope); HttpTransportSE ht=new HttpTransportSE(serviceURL); ht.debug=true; try { ht.call("http://tempuri.org/HelloWorld", envelope); if(envelope.getResponse()!=null){ message=envelope.bodyIn.toString(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } return message; } }
HelloWSActivity类代码:
- Java code
package com.dai.hellows; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloWSActivity extends Activity { private TextView helloTV; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); helloTV=(TextView)findViewById(R.id.helloTV); String message=WSUtils.getMessage(); System.out.println("message="+message); helloTV.setText(message); } }
------解决方案--------------------
这个不是你的错误吧,是服务器端的错误,C:WINDOWSTEMP zirsksq.0.cs 服务器端没有这个文件