为什么我无法从网络服务获得结果?当我调试代码时,它显示异常。
以下代码适用于Web服务请求。
@SuppressWarnings("deprecation")
protected boolean UserNameAvailability(final String sUserName)
{
boolean result = false;
SoapObject request = new SoapObject(getResources().getString(R.string.targetnamespace), getResources().getString(R.string.usernameavailabilitymethod));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
PropertyInfo piUserName = new PropertyInfo();
piUserName.name = "UserName";
request.addProperty(piUserName, sUserName);
HttpTransportSE httpTransport = new HttpTransportSE(getResources().getString(R.string.webserviceurl));
try {
httpTransport.debug =true;
httpTransport.call(getResources().getString(R.string.usernameavailabilitysoapaction), envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
if (!response.toString().equals("false")) {
result = true;
}
//else
//{
// alertBox("User Name already exists.Please enter different username.");
// }
}catch (Exception exception) {
Log.w("UserNameAvailability - RegisterActivity", "Error message is "+exception.getMessage(), exception);
}
return result;
}
记录猫的详细信息
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at android.os.Looper.loop(Looper.java:123)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at java.lang.reflect.Method.invokeNative(Native Method)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at java.lang.reflect.Method.invoke(Method.java:521)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241): at dalvik.system.NativeStart.main(Native Method)
01-16 18:13:43.946: I/ActivityManager(51): Displayed activity com.anb.eCalculator/.LoginActivity: 1988 ms (total 1988 ms)
01-16 18:13:45.996: I/ActivityManager(51): Starting activity: Intent { cmp=com.anb.eCalculator/.RegisterActivity }
01-16 18:13:56.002: W/ActivityManager(51): Launch timeout has expired, giving up wake lock!
01-16 18:13:56.073: W/ActivityManager(51): Activity idle timeout for HistoryRecord{44d9f420 com.anb.eCalculator/.RegisterActivity}
01-16 18:14:00.764: I/ActivityManager(51): Displayed activity com.anb.eCalculator/.RegisterActivity: 14756 ms (total 14756 ms)
01-16 18:14:16.317: W/KeyCharacterMap(241): No keyboard for id 0
01-16 18:14:16.317: W/KeyCharacterMap(241): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-16 18:14:18.587: D/ViewFlipper(91): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
01-16 18:14:18.587: D/ViewFlipper(91): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
答案 0 :(得分:0)
@Prakash查看下面的代码,该代码从活动中调用Web服务
public class FirstAppUI extends Activity
{
private static final String NAMESPACE = "test.org";
private static final String URL =
"http://localhost:8080/AndriodBackend/services/listServices/server-config.wsdd";
private static final String SOAP_ACTION = "Test";
private static final String METHOD_NAME = "rate";
private static final String[] sampleACTV = new String[] {"android", "iphone", blackberry"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> arrAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_dropdown_item_1line, sampleACTV);
AutoCompleteTextView ACTV = (AutoCompleteTextView)findViewById
(R.id.AutoCompleteTextView01);
ACTV.setAdapter(arrAdapter);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
ACTV.setHint("Received :" + resultsRequestSOAP.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
答案 1 :(得分:0)
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
if (!response.toString().equals("false"))
result = true;
尝试使用以下内容可能会解决您的问题。
SoapObject resultRequestSOAP = (SoapObject) envelope.bodyIn;
String resultString = resultRequestSOAP.getProperty(0).toString();
resultString你得到的结果是真或假。