Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:使用ksoap2调用Web服务_Android_Web Services_Ksoap2_Webservice Client_Android Ksoap2 - Fatal编程技术网

Android:使用ksoap2调用Web服务

Android:使用ksoap2调用Web服务,android,web-services,ksoap2,webservice-client,android-ksoap2,Android,Web Services,Ksoap2,Webservice Client,Android Ksoap2,我已经创建了一个Web服务来执行添加。我创建了一个Android应用程序来使用该Web服务并在TextView中显示输出。请在下面找到WSDL和代码 WSDL 代码 main.xml AndroidManifest.xml 我觉得Web服务没有被调用。我已经使用文本视图来显示输出。请帮我解决这个问题。我没有得到任何输出: 即使加入 Log.eObject response,response.toString 我在LogCat里什么都看不到 非常感谢 URL是http://localhost:80

我已经创建了一个Web服务来执行添加。我创建了一个Android应用程序来使用该Web服务并在TextView中显示输出。请在下面找到WSDL和代码

WSDL

代码

main.xml

AndroidManifest.xml

我觉得Web服务没有被调用。我已经使用文本视图来显示输出。请帮我解决这个问题。我没有得到任何输出:

即使加入 Log.eObject response,response.toString

我在LogCat里什么都看不到

非常感谢

URL是http://localhost:8080/Monish/TestWebservice?WSDL
这意味着web服务正在android设备上侦听?

是!但我相信webserive不会被称为。我在LogCat Either中看不到响应。在这种情况下,您应该使用WSDL中的服务URL位置,而不是WSDL URL。@SandroProxysupport-Web服务是使用WebMethodsJavaPlatform创建的。事实上,WS是在哪种技术中创建的,这有关系吗?我不确定,请澄清。我只是确保你没有犯这个错误:还有什么可能是错误的。。。检查android设备上的服务是否真的在端口8080上等待来自adb shell的netstat,使用其他android应用程序发出相同的请求我假设您的android和服务器在同一台机器上,因为您使用的是localhost?如果是,localhost将被视为android的仿真器,您应该使用IP10.0.2.2而不是localhost。看见
<wsdl:definitions 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapjms="http://www.w3.org/2010/soapjms/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://localhost:8080/Monish/TestWebservice"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"name="TestWebservice"
targetNamespace="http://localhost:8080/Monish/TestWebservice">
<wsdl:types>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:tns="http://localhost:8080/Monish/TestWebservice"
 targetNamespace="http://localhost:8080/Monish/TestWebservice">
   <xsd:element name="myTest" type="tns:myTest"/>
   <xsd:element name="myTestResponse" type="tns:myTestResponse"/>
 <xsd:complexType name="myTest">
   <xsd:sequence>
    <xsd:element name="a" nillable="true" type="xsd:string"/>
    <xsd:element name="b" nillable="true" type="xsd:string"/>
   </xsd:sequence>
   </xsd:complexType>
 <xsd:complexType name="myTestResponse">
 <xsd:sequence>
<xsd:element name="output" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
 <wsdl:message name="TestWebservice_PortType_myTestResponse">
<wsdl:part name="parameters" element="tns:myTestResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="TestWebservice_PortType_myTest">
<wsdl:part name="parameters" element="tns:myTest"></wsdl:part>
</wsdl:message>
<wsdl:portType name="TestWebservice_PortType">
<wsdl:operation name="myTest">
<wsdl:input message="tns:TestWebservice_PortType_myTest"></wsdl:input>
<wsdl:output message="tns:TestWebservice_PortType_myTestResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Monish_TestWebservice_Binder" type="tns:TestWebservice_PortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="myTest">
<soap:operation soapAction="Monish_TestWebservice_Binder_myTest" style="document"/>
<wsdl:input>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output>
 <soap:body parts="parameters" use="literal"/>
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
<wsdl:service name="TestWebservice">
<wsdl:port name="Monish_TestWebservice_Port" binding="tns:Monish_TestWebservice_Binder">
 <soap:address location="http://localhost:8080/ws/Monish:TestWebservice/Monish_TestWebservice_Port"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
package com.webservice;

public class WebServiceDemoActivity extends Activity {
private final String NAMESPACE = "http://localhost:8080/Monish/TestWebservice/"; 
private final String URL = "http://localhost:8080/Monish/TestWebservice?WSDL";
private final String SOAP_ACTION = "Monish_TestWebservice_Binder_myTest";  
private final String METHOD_NAME = "myTest"; 

    ArrayList<Guard> guardList=new ArrayList<Guard>();
    // Called when the activity is first created.
    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo propInfo=new PropertyInfo();
        propInfo.type=PropertyInfo.INTEGER_CLASS;
                    //adding parameters
        request.addProperty("a", 10);
        request.addProperty("b", 15);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = false;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();


            Log.e("Object response", response.toString());
            TextView tv = new TextView(this);
            tv.setText("Output: "+response.toString());
            setContentView(tv);
        } catch (Exception e) {
                e.printStackTrace();
            }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

   <TextView
   android:id="@+id/textView1"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="" />


</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webservice"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.webservice.WebServiceDemoActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>