你好,我是安卓新手。
我正在尝试使用 glassfish 将我的 android 应用程序与我用 java 制作的 web 服务连接起来。
这是我的 WSDL。
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://TicketingServices/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://TicketingServices/" name="TicketingServices">
<types>
<xsd:schema>
<xsd:import namespace="http://TicketingServices/" schemaLocation="http://localhost:8080/TicketingService/TicketingServices?xsd=1"/>
</xsd:schema>
</types>
<message name="login">
<part name="parameters" element="tns:login"/>
</message>
<message name="loginResponse">
<part name="parameters" element="tns:loginResponse"/>
</message>
<message name="ola">
<part name="parameters" element="tns:ola"/>
</message>
<message name="olaResponse">
<part name="parameters" element="tns:olaResponse"/>
</message>
<message name="teste">
<part name="parameters" element="tns:teste"/>
</message>
<message name="testeResponse">
<part name="parameters" element="tns:testeResponse"/>
</message>
<portType name="TicketingServices">
<operation name="login">
<input wsam:Action="http://TicketingServices/TicketingServices/loginRequest" message="tns:login"/>
<output wsam:Action="http://TicketingServices/TicketingServices/loginResponse" message="tns:loginResponse"/>
</operation>
<operation name="ola">
<input wsam:Action="http://TicketingServices/TicketingServices/olaRequest" message="tns:ola"/>
<output wsam:Action="http://TicketingServices/TicketingServices/olaResponse" message="tns:olaResponse"/>
</operation>
<operation name="teste">
<input wsam:Action="http://TicketingServices/TicketingServices/testeRequest" message="tns:teste"/>
<output wsam:Action="http://TicketingServices/TicketingServices/testeResponse" message="tns:testeResponse"/>
</operation>
</portType>
<binding name="TicketingServicesPortBinding" type="tns:TicketingServices">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="login">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="ola">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="teste">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="TicketingServices">
<port name="TicketingServicesPort" binding="tns:TicketingServicesPortBinding">
<soap:address location="http://localhost:8080/TicketingService/TicketingServices"/>
</port>
</service>
</definitions>
这是我的 androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pt.ubi.tecketing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TecketingAppActivity"
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>
这是我的 Androidapp 代码
package pt.ubi.tecketing;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.HttpsTransportSE;
public class TecketingAppActivity extends Activity {
private static final String URL = "http://192.168.1.159:8080/TicketingService/TicketingServices?wsdl";
private static final String METHOD_NAME = "teste";
private static final String SOAP_ACTION = "TicketingServices";
private static final String NAMESPACE = "http://TicketingServices/";
TextView lblAviso;
String resultsRequestSOAP;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lblAviso = (TextView) findViewById(R.id.lblAvisoInternet);
//Criando os padâmetros de entrada
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//request.addProperty("texto", "ola");
//Envelope SOAP
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
lblAviso.setText("AQUI1");
//Chamada ao WS
androidHttpTransport.call(SOAP_ACTION, envelope);
lblAviso.setText("AQUI2");
//String com o retorno
resultsRequestSOAP = (String) envelope.getResponse();
lblAviso.setText("teste"+resultsRequestSOAP);
} catch (Exception e) {
lblAviso.setText("ERRO");
}
}
}
这是我的 Web 服务代码。
@WebService(serviceName = "TicketingServices", targetNamespace ="http://TicketingServices/")
public class TicketingServices {
@WebMethod(operationName = "login")
public String login(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "server") final String server) {
return username;
}
@WebMethod(operationName = "ola")
public String ola(@WebParam(name = "texto") String texto) {
return texto;
}
@WebMethod(operationName = "teste")
public String teste() {
return "Ola";
}
}
感谢您的帮助。