Ich entwickle eine Android-Anwendung mit Hintergrund-Service, die eine Methode eines Web-Service auf alle 5 Minuten verbraucht. Ich verwende ksoap 2.4 und asp.net Webservice. Der Android-Hintergrunddienst läuft alle 5 Minuten, aberAndroid Hintergrund Service ksoap Fehler
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
gibt null zurück. hier ist mein Android Service-Code.
package com.example.rashid.challandb;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.MarshalBase64;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class TestService extends Service {
private static String NAMESPACE = "http://tempuri.org/";
private static String URL = "http://192.168.50.107:80/AndroidService/Service1.asmx";
private static String SOAP_ACTION = "http://tempuri.org/";
Context context;
boolean isrunning;
public TestService() {
}
@Override
public void onCreate()
{
this.context=this;
this.isrunning=false;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent,int flags,int startid) {
if (!this.isrunning) {
this.isrunning = true;
synchronized (this) {
try {
String resTxt = "default";
String webMethName="MyMethod";
SoapObject request = new SoapObject(NAMESPACE, webMethName);
PropertyInfo first = new PropertyInfo();
first.setName("Para");
first.setValue("Hullow");
first.setType(String.class);
request.addProperty(first);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
Object response = null;
response = (Object) envelope.getResponse();
resTxt =response.toString();
} catch (Exception e) {
e.printStackTrace();
System.out.println( e.getMessage()+" Phone");
}
System.out.println( resTxt);
} catch (Exception ex) {
System.out.println("Error:" + ex.getMessage());
}
this.isrunning = false;
stopSelf();
}
}
return START_STICKY;
}
@Override
public void onDestroy()
{
this.isrunning=false;
}
}
hier ist die Wsdl
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="MyMethod">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Para" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="MyMethodResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="MyMethodResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="MyMethodSoapIn">
<wsdl:part name="parameters" element="tns:MyMethod"/>
</wsdl:message>
<wsdl:message name="MyMethodSoapOut">
<wsdl:part name="parameters" element="tns:MyMethodResponse"/>
</wsdl:message>
<wsdl:portType name="Service1Soap">
<wsdl:operation name="MyMethod">
<wsdl:input message="tns:MyMethodSoapIn"/>
<wsdl:output message="tns:MyMethodSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="MyMethod">
<soap:operation soapAction="http://tempuri.org/MyMethod" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="Service1Soap12" type="tns:Service1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="MyMethod">
<soap12:operation soapAction="http://tempuri.org/MyMethod" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1">
<wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="http://192.168.50.107/AndroidService/Service1.asmx"/>
</wsdl:port>
<wsdl:port name="Service1Soap12" binding="tns:Service1Soap12">
<soap12:address location="http://192.168.50.107/AndroidService/Service1.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
u r jede Ausnahme in Fang bekommen? –
ja bei Aufruf gibt es eine Ausnahme "null" –
können Sie Ihre PLZ post wsdl? –