2

今、私はAndroidEclipseからWebサービスを利用するためにSOAPメソッドを使用しました。

edittextから入力を取得し、適切な値を表示する必要があります。つまり、Webサービスを呼び出して結果を返す必要があります。

エミュレータが実行されると、「ERROR:java.lang.RuntimeException:Cannotserialize0004」と表示されます。このエラーを解決するにはどうすればよいですか。

これが私のコードです、見つけてください

screen.java

public class X_classActivity extends Activity 
{
    private EditText edit;
    private Button btn; 

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         edit = (EditText) findViewById(R.id.editText1); 
         btn = (Button)findViewById(R.id.button1);
         btn.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                      fun();
             }
         });
   }

private void fun()
{
    //getSOAPResponse() method returns SOAP Response
    SoapObject soapResponseObject = getSOAPResponse(edit.getText());
}

public SoapObject getSOAPResponse(GetChars search)
{
    SoapObject soapObject = new SoapObject("http://tempuri.org/", "GetName");
    soapObject.addProperty("str", search);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(soapObject);
    HttpTransportSE androidHttpTransport = new      HttpTransportSE("http://122.248.240.105:234/Service1.asmx?WSDL");
    try 
    {
         androidHttpTransport.call("http://tempuri.org/GetName", envelope);//call the eb service Method
         Object result = envelope.getResponse();
         System.out.println(" " + result.toString());
         ((TextView) findViewById (R.id.textView2)).setText(""+result.toString());
    } 
    catch (Exception E) 
    {
         E.printStackTrace();
         ((TextView) findViewById (R.id.textView2)).setText("ERROR:"    + E.getClass().getName() + ":" + E.getMessage());
    }
    return soapObject;
   }
}

Logcat

06-01 18:39:56.020: W/KeyCharacterMap(932): No keyboard for id 0
06-01 18:39:56.020: W/KeyCharacterMap(932): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-01 18:40:00.510: W/System.err(932): java.lang.RuntimeException: Cannot serialize: 0004
06-01 18:40:00.520: W/System.err(932):  at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:661)
06-01 18:40:00.520: W/System.err(932):  at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:645)
06-01 18:40:00.520: W/System.err(932):  at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:614)
06-01 18:40:00.520: W/System.err(932):  at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:598)
06-01 18:40:00.520: W/System.err(932):  at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:655)
06-01 18:40:00.530: W/System.err(932):  at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:579)
06-01 18:40:00.530: W/System.err(932):  at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192)
06-01 18:40:00.530: W/System.err(932):  at org.ksoap2.transport.Transport.createRequestData(Transport.java:74)
06-01 18:40:00.530: W/System.err(932):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:58)
06-01 18:40:00.530: W/System.err(932):  at com.x.x.x.X_classActivity.getSOAPResponse(X_classActivity.java:57)
06-01 18:40:00.530: W/System.err(932):  at com.x.x.x.X_classActivity.fun(X_classActivity.java:45)
06-01 18:40:00.530: W/System.err(932):  at com.x.x.x.X_classActivity.access$0(X_classActivity.java:41)
06-01 18:40:00.530: W/System.err(932):  at com.x.x.x.X_classActivity$1.onClick(X_classActivity.java:36)
06-01 18:40:00.530: W/System.err(932):  at android.view.View.performClick(View.java:2408)
06-01 18:40:00.530: W/System.err(932):  at android.view.View$PerformClick.run(View.java:8816)
06-01 18:40:00.530: W/System.err(932):  at android.os.Handler.handleCallback(Handler.java:587)
06-01 18:40:00.530: W/System.err(932):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-01 18:40:00.530: W/System.err(932):  at android.os.Looper.loop(Looper.java:123)
06-01 18:40:00.530: W/System.err(932):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-01 18:40:00.530: W/System.err(932):  at java.lang.reflect.Method.invokeNative(Native Method)
06-01 18:40:00.530: W/System.err(932):  at java.lang.reflect.Method.invoke(Method.java:521)
06-01 18:40:00.540: W/System.err(932):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-01 18:40:00.540: W/System.err(932):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-01 18:40:00.540: W/System.err(932):  at dalvik.system.NativeStart.main(Native Method)

ウェブメソッド

 public class GetName {
public String GetName(String str){
    return(str);
}    }

どうもありがとう!!..

4

1 に答える 1

0

私はあなたがこの行で何か間違ったことをしていると思います、

androidHttpTransport.call("http://tempuri.org/GetName", envelope);//call the eb service Method

最初の議論は間違っていると思います。次のコードを参照してください、それは私にとってはうまくいきます。また、プロジェクトをビルドするときに依存関係をエクスポートしてください。時々それはあなたを助けるでしょう。

    private String METHOD_NAME = "";
    // our webservice method name
    private String NAMESPACE = "http://ws.travel_ceylon.web.org";
    // Here package name in webservice with reverse order.
    private String SOAP_ACTION = NAMESPACE + METHOD_NAME;
    // NAMESPACE + method name
    private static final String URL = "http://192.168.177.130:8080/Travel_Ceylon_Central_Web_Service/services/Travel_Ceylon_Web_Service?wsdl";

    // you must use ipaddress here, don’t use Hostname or localhost

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String city = "Matara";
        String im = "Galle Face";

        METHOD_NAME = "getLongitude_City";
        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("city", city);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            Object result = envelope.getResponse();
            ((TextView) findViewById(R.id.txtCityLongitude)).setText(city
                    + " Longitude is : " + result.toString());

        } catch (Exception E) {
            E.printStackTrace();
            ((TextView) findViewById(R.id.txtCityLongitude)).setText("ERROR:"
                    + E.getClass().getName() + ":" + E.getMessage());
        }
于 2012-06-12T02:42:48.937 に答える