我正在使用基于肥皂的网络服务..我使用了这个example n我能够进行解析并获得响应,但是当我通过对其进行一些更改来尝试不同的时候。我在我的项目中得到了下面提到的错误我的代码在下面请看看..
public class MainActivity extends ActionBarActivity implements OnClickListener {
TextView tv1;
EditText edname, edemail, edpassword;
Button btnSubmit;
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://208.109.86.236:8080/API.asmx";
private final String SOAP_ACTION = "http://tempuri.org/PlayerSignup";
private final String METHOD_NAME = "PlayerSignup";
private String TAG = "PGGURU";
private static String stusername;
private static String stpassword;
private static String stemail;
private static String responsea;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tv1);
edname = (EditText) findViewById(R.id.editText1);
edpassword = (EditText) findViewById(R.id.editText2);
edemail = (EditText) findViewById(R.id.editText3);
btnSubmit = (Button) findViewById(R.id.button1);
btnSubmit.setOnClickListener(this);
// throw new RuntimeException();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (edname.getText().toString() != ""
&& edpassword.getText().toString() != ""
&& edemail.getText().toString() != "") {
stusername = edname.getText().toString();
stpassword = edpassword.getText().toString();
stemail = edemail.getText().toString();
Log.i("username", stusername);
Log.i("password", stpassword);
Log.i("email", stemail);
AsyncCallWS task = new AsyncCallWS();
// Call execute
task.execute();
} else {
tv1.setText("Please enter Celcius");
}
}
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
Log.i(TAG, "doInBackground");
getFahrenheit(stusername, stpassword, stemail);
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
tv1.setText(responsea);
}
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
tv1.setText("Calculating...");
}
@Override
protected void onProgressUpdate(Void... values) {
Log.i(TAG, "onProgressUpdate");
}
}
public void getFahrenheit(String name, String password, String email) {
// Create request
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Property which holds input parameters
PropertyInfo celsiusPI = new PropertyInfo();
// Set Name
celsiusPI.setName("Username");
// Set Value
celsiusPI.setValue(stusername);
celsiusPI.setName("Password");
// Set Value
celsiusPI.setValue(stpassword);
celsiusPI.setName("Email");
// Set Value
celsiusPI.setValue(stemail);
// Set dataType
celsiusPI.setType(String.class);
// Add the property to request object
request.addProperty(celsiusPI);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invole web service
Log.i("aaaa", "aaaaaaaaaaa");
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.i("bbbb", "bbbbbbbbbbbbbbb");
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// SoapObject response = (SoapObject) envelope.getResponse();
// Object result= (Object)envelope.getResponse();
Log.i("cccc", "ccccccccccccc");
// Assign it to fahren static variable
responsea = response.toString();
Log.i("dddd", "dddddddddddd");
} catch (Exception e) {
e.printStackTrace();
}
}
}
我在这一行得到例外
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
logcat的:
11-10 17:24:22.108: I/username(25790): fgg
11-10 17:24:22.108: I/password(25790): fhgg
11-10 17:24:22.108: I/email(25790): cbbb
11-10 17:24:22.108: I/PGGURU(25790): onPreExecute
11-10 17:24:22.108: I/PGGURU(25790): doInBackground
11-10 17:24:22.108: I/aaaa(25790): aaaaaaaaaaa
11-10 17:24:23.480: I/bbbb(25790): bbbbbbbbbbbbbbb
11-10 17:24:23.480: W/System.err(25790): SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: String reference not set to an instance of a String.
11-10 17:24:23.480: W/System.err(25790): Parameter name: s
11-10 17:24:23.480: W/System.err(25790): at System.Text.Encoding.GetBytes(String s)
11-10 17:24:23.480: W/System.err(25790): at IndiablWebService.Helper.CryptorEngine.Encrypt(String toEncrypt, Boolean useHashing) in C:\Users\DIGICOM\Desktop\IndiablWebService_New1\IndiablWebService_New_from office\IndiablWebService\Helper\CryptorEngine.cs:line 22
11-10 17:24:23.480: W/System.err(25790): at IndiablWebService.API.DokPlayerSignup(String Username, String Password, String Email, String Question, String Answer) in C:\Users\DIGICOM\Desktop\IndiablWebService_New1\IndiablWebService_New_from office\IndiablWebService\API.asmx.cs:line 124
11-10 17:24:23.480: W/System.err(25790): at IndiablWebService.API.PlayerSignup(String Username, String Password, String Email) in C:\Users\DIGICOM\Desktop\IndiablWebService_New1\IndiablWebService_New_from office\IndiablWebService\API.asmx.cs:line 87
11-10 17:24:23.480: W/System.err(25790): --- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@4181f468
11-10 17:24:23.480: W/System.err(25790): at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:112)
11-10 17:24:23.480: W/System.err(25790): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)
11-10 17:24:23.480: W/System.err(25790): at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
11-10 17:24:23.480: W/System.err(25790): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
11-10 17:24:23.480: W/System.err(25790): at com.example.soap_demo2.MainActivity.getFahrenheit(MainActivity.java:136)
11-10 17:24:23.480: W/System.err(25790): at com.example.soap_demo2.MainActivity$AsyncCallWS.doInBackground(MainActivity.java:74)
11-10 17:24:23.480: W/System.err(25790): at com.example.soap_demo2.MainActivity$AsyncCallWS.doInBackground(MainActivity.java:1)
11-10 17:24:23.480: W/System.err(25790): at android.os.AsyncTask$2.call(AsyncTask.java:288)
11-10 17:24:23.480: W/System.err(25790): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-10 17:24:23.480: W/System.err(25790): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
11-10 17:24:23.480: W/System.err(25790): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-10 17:24:23.480: W/System.err(25790): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
11-10 17:24:23.480: W/System.err(25790): at java.lang.Thread.run(Thread.java:841)
11-10 17:24:23.480: I/PGGURU(25790): onPostExecute
答案 0 :(得分:8)
我刚刚导航到http://208.109.86.236:8080/API.asmx?op=PlayerSignup
并执行了测试请求。我收到了这个回复:
{"LoginStatus":true,"Message":"Successfully Registered","AccessToken":"dfUW4Xq8u1w="}
这是JSON。 SOAP协议在XML上运行。您需要更改服务器以在适当的XML架构中返回数据。