如何从SOAP构建SOAP请求,如SOAP UI请求?

时间:2017-07-16 22:43:40

标签: android soap soapui android-ksoap2

最近我正在对我的Android应用程序进行debbuging,但是当我从我的Web服务接收数据时遇到了问题,因为在日志中,它说我发送的参数(List)是空的......事情就是这样。 ..当我用SOAP UI测试我的方法时,它工作!我得到了我想要的东西,但是从android开始,xml请求的构建方式与XML不同:

SOAP UI(此XML Works!):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ws="http://ws.soap.net/">
   <soapenv:Header/>
<soapenv:Body>
  <ws:GetSomething>
     <!--Zero or more repetitions:-->
     <List>
        <!--Optional:-->
        <id>000001</id>
        <!--Optional:-->
        <type>Sign</type>
     </List>
  </ws:GetSomething>

如您所见,这是SOAP UI为我的ws

请求构建的xml

这是我在Android上调试时发现的XML:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:d="http://www.w3.org/2001/XMLSchema" 
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<n0:GetSomething xmlns:n0="http://ws.soap.net/">
<n0:List>
<id>000001</id>
<tipo>sign</tipo>
<id>000002</id>
<tipo>sign</tipo>
<id>000003</id>
<tipo>sign</tipo>
</n0:List>
</n0:GetSomething>
</v:Body>
</v:Envelope>

所以在Android上调试时生成的xml,当我粘贴在SOAP UI上时,只是说我发送的参数(一个List)是空的......

我测试了在Android中生成的XML,只有在我删除&#34; n0&#34;前缀&#34;列表&#34;我的意思是:

从这个:          

到此:

<List>
</List>

这是我的Android SOAP请求:

  private final String SOAP_NAMESPACE = "http://ws.soap.net/";
private final StringURL_SOAP="http://MI_IP:PORT/GetSomeRest/WebServiceTest";
private final String SOAP_SOMETHING = "GetSomething";
private final String SOAP_ACTION_GETSOMETHING = "http://ws.soap.net/" + SOAP_SOMETHING;
    public SoapObject SendSigns(ArrayList<Signs> paramSigns)
{       
SoapObject request = new SoapObject(SOAP_NAMESPACE, SOAP_SOMETHING);

request.addSoapObject(buildArray(paramSigns));

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);

new MarshalBase64().register(envelope);
envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
envelope.setAddAdornments(false);
envelope.implicitTypes= true;
envelope.dotNet=true;
envelope.headerOut = new org.kxml2.kdom.Element[1];

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_SOAP);

try {
    androidHttpTransport.debug = true;

    androidHttpTransport.call(SOAP_ACTION_GETSOMETHING, envelope);

    SoapObject Object = (SoapObject) envelope.getResponse();

    if(Object!=null)
    {
        return Object;
    }

} catch (Exception e) {
    Log.d("CALL DUMP", "requestError: "+androidHttpTransport.requestDump);
    Log.d("CALL DUMP", "responseEror: "+androidHttpTransport.responseDump);
    Log.e("ERROR: ", String.valueOf(e));

}        
return null;

}

1 个答案:

答案 0 :(得分:0)

你是否在URL_SOAP和String之间加了空格?

这是你的代码:

private final StringURL_SOAP="http://MI_IP:PORT/GetSomeRest/WebServiceTest";

正确:

private final String URL_SOAP="http://MI_IP:PORT/GetSomeRest/WebServiceTest";