android - SoapFault - 错误代码 : 'soap:Server' faultstring: 'System. Web.Services.Protocols.SoapException:

标签 android web-services soap

我正在使用 soap base 网络服务.. 我使用了这个 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();

日志:

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

最佳答案

我刚刚导航到 http://208.109.86.236:8080/API.asmx?op=PlayerSignup 并执行了一个测试请求。我得到了这样的回复:

{"LoginStatus":true,"Message":"Successfully Registered","AccessToken":"dfUW4Xq8u1w="}

这是 JSON。 SOAP 协议(protocol)对 XML 进行操作。您需要更改服务器以在适当的 XML 架构中返回数据。

关于android - SoapFault - 错误代码 : 'soap:Server' faultstring: 'System. Web.Services.Protocols.SoapException:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26843433/

相关文章:

ruby-on-rails - 无法找到 SOAP 操作 RAILS + SAVON

java - 为Java Jersey Restful Web服务添加身份验证机制

java - Apache Camel CXF

c# - 在 C# 中,在 DLL 中捕获 SOAP

android - 如何隐藏主 Activity 的标题栏?

android - 如何在 Android 启动前挂载 ramdisk?

android - RatingBar 设置前延迟提交

android - 这可行,但它是 "right"方式吗?

c# - 枚举的版本

java - 运行时动态 Web 服务调用