【问题标题】:How to build a SOAP Request from android like SOAP UI request?如何像 SOAP UI 请求一样从 android 构建 SOAP 请求?
【发布时间】:2017-07-16 22:43:40
【问题描述】:

最近我正在调试我的 Android 应用程序,但是在从我的 Web 服务接收数据时遇到问题,因为在日志中,它说我发送的参数(列表)为空......事情是这样的。 ..当我用 SOAP UI 测试我的方法时,它可以工作!!我得到了我想要的,但是从 android 构建的 xml 请求不同这里是 XML:

SOAP UI(此 XML 有效!):

<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上时,只是说我发送的参数(一个列表)是空的......

我测试了在 Android 中生成的 XML,并且只有在我删除“列表”之前的“n0”前缀我的意思是:

从此:

到这里:

<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;

}

【问题讨论】:

    标签: android soap soapui android-ksoap2


    【解决方案1】:

    您是否在 URL_SOAP 和 String 之间放置了空格?

    这是你的代码:

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

    正确:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-22
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多