Android 如何通过ksoap2创建SOAP请求 000D6F0000

Android 如何通过ksoap2创建SOAP请求 000D6F0000,android,web-services,soap,ksoap2,Android,Web Services,Soap,Ksoap2,我在一个android项目中工作,我想使用一些JAX-WS。这些服务是由其他人提供的,所以我不能对它们进行任何更改。我想用这些编写的代码发送上面的SOAP消息,但调用它们时我收到的唯一消息是java.lang.NullPointerException <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <

我在一个android项目中工作,我想使用一些JAX-WS。这些服务是由其他人提供的,所以我不能对它们进行任何更改。我想用这些编写的代码发送上面的SOAP消息,但调用它们时我收到的唯一消息是java.lang.NullPointerException

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header/>
    <S:Body>
        <ns2:FReadStatus xmlns:ns2="http://poweb13/">
            <arg0>000D6F0000</arg0>
        </ns2:FReadStatus>
    </S:Body>
</S:Envelope>
private静态最终字符串命名空间=”http://poweb13/";
私有静态最终字符串URL=”http://smart.gr:8080/aWESoME/SmartPlugService?wsdl"; 
私有静态最终字符串SOAP\u ACTION=“SmartPlugService”;
私有静态最终字符串方法\u NAME=“FReadStatus”;
SoapObject请求=新的SoapObject(名称空间、方法名称);
PropertyInfo p1=新的PropertyInfo();
p1.设置名称(“MAC”);
p1.设定值(“000D6F0000”);
p1.setType(myDevice.getmac().toString().getClass());
请求。添加属性(p1);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(请求);
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
试试{
androidHttpTransport.setXmlVersionTag(“”);
调用(SOAP_操作,信封);
SoapObject resultsRequestSOAP=(SoapObject)envelope.bodyIn;
字符串结果=resultsRequestSOAP.getProperty(“返回”).toString();
Log.i(“信息”,“收到:+结果”);
}catch(java.lang.ClassCastException e){
SoapFault故障=(SoapFault)envelope.bodyIn;
Log.e(“error”,“Received:”+fault.getMessage().toString());
Log.e(“error”,“Received:”+fault.getLocalizedMessage().toString());
StackTraceElement[]st=fault.getStackTrace();

对于(int i=0;iOk),你有一个函数FReadStatus:

SOAP Response

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:FReadStatusResponse xmlns:ns2="http://poweb13/">
            <return>1</return>
        </ns2:FReadStatusResponse>
    </S:Body>
</S:Envelope>
现在您拥有了该类,您将在您拥有的代码中执行以下操作:

public class FReadStatus implements KvmSerializable {

String mac; 

@Override
public Object getProperty(int arg0) {
switch (arg0){
    case 0:
        return mac;
    default:
        return null;
        }
}

@Override
public int getPropertyCount() {
    return 1;//because you have 1 parameter
}

@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{

    case 0:
        arg2.type = PropertyInfo.STRING_CLASS;//because its type is string
        arg2.name = "arg0";
        break;
    default:break;
}

}

@Override
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
    case 0:
        mac=  (String)arg1;
        break;
    default:
        break;
}
}
让我知道wt的发生。您必须使用来检查requestDump和responseDump

更新:回答您关于UnknowHostException的问题
可能的原因和解决方案

  • 检查您的AndroidManifest.xml中是否有:

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    
        PropertyInfo pi = new PropertyInfo();
        pi.setName("arg0");
        pi.setValue("000D6F0000");
        pi.setType(FReadStatus .class);
        request.addProperty(pi);
    
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
        envelope.setOutputSoapObject(request);
    
         //Now you have to add mapping to map the local class created, to the one on the server
        envelope.addMapping(NAMESPACE , FReadStatus.class.getSimpleName(), FReadStatus .class);
    
        // Add marshalling (this one might not be necessary, but ill just add it)
        Marshal floatMarshal = new MarshalFloat();
        floatMarshal.register(envelope);
    
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);//AndroidHttpTransport INSTEAD OF HttpTransportSE 
    
        androidHttpTransport.debug = true;//NEW ADDED
        try {           
    
            androidHttpTransport.call(SOAP_ACTION, envelope);
    
           //Important Outputs to check how the request/Response looks like.. Check them in Logcat to find these outputs
           System.out.println("requestDump is :"+androidHttpTransport.requestDump);
           System.out.println("responseDump is :"+androidHttpTransport.responseDump);
           System.out.println("response"+envelope.getResponse());
    
        } catch (Exception e){}
    
  • 您可能需要对dns进行预热,请检查此项

SOAP Response

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:FReadStatusResponse xmlns:ns2="http://poweb13/">
            <return>1</return>
        </ns2:FReadStatusResponse>
    </S:Body>
</S:Envelope>
<message name="FReadStatus">
  <part name="parameters" element="tns:FReadStatus"/>
</message>
<xs:complexType name="FReadStatus">
  <xs:sequence>
    <xs:element name="arg0" type="xs:string" minOccurs="0"/>
  </xs:sequence>
</xs:complexType>
public class FReadStatus implements KvmSerializable {

String mac; 

@Override
public Object getProperty(int arg0) {
switch (arg0){
    case 0:
        return mac;
    default:
        return null;
        }
}

@Override
public int getPropertyCount() {
    return 1;//because you have 1 parameter
}

@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{

    case 0:
        arg2.type = PropertyInfo.STRING_CLASS;//because its type is string
        arg2.name = "arg0";
        break;
    default:break;
}

}

@Override
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
    case 0:
        mac=  (String)arg1;
        break;
    default:
        break;
}
}
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    PropertyInfo pi = new PropertyInfo();
    pi.setName("arg0");
    pi.setValue("000D6F0000");
    pi.setType(FReadStatus .class);
    request.addProperty(pi);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request);

     //Now you have to add mapping to map the local class created, to the one on the server
    envelope.addMapping(NAMESPACE , FReadStatus.class.getSimpleName(), FReadStatus .class);

    // Add marshalling (this one might not be necessary, but ill just add it)
    Marshal floatMarshal = new MarshalFloat();
    floatMarshal.register(envelope);

    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);//AndroidHttpTransport INSTEAD OF HttpTransportSE 

    androidHttpTransport.debug = true;//NEW ADDED
    try {           

        androidHttpTransport.call(SOAP_ACTION, envelope);

       //Important Outputs to check how the request/Response looks like.. Check them in Logcat to find these outputs
       System.out.println("requestDump is :"+androidHttpTransport.requestDump);
       System.out.println("responseDump is :"+androidHttpTransport.responseDump);
       System.out.println("response"+envelope.getResponse());

    } catch (Exception e){}
<uses-permission android:name="android.permission.INTERNET" />
System.setProperty("http.proxyHost", "my.proxyhost.com");
System.setProperty("http.proxyPort", "1234");