2

我必须提出以下soap请求,但我们无法成功,我尝试了几种方法都失败了,我总是得到一个空白字段作为响应。

请求应如下所示:

POST /service.asmx HTTP/1.1
Host: host
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "SOAPAction"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetQuickParkEvents xmlns="NAMESPACE">
      <User>
        <ID>int</ID>
        <Name>string</Name>
        <UserName>string</UserName>
        <Password>string</Password>
      </User>
      <Filter>
        <TimeSpan>
          <Since>dateTime</Since>
          <To>dateTime</To>
        </TimeSpan>
        <Reg>string</Reg>
        <Nalog>string</Nalog>
        <Status>string</Status>
        <Value>string</Value>
      </Filter>
    </GetQuickParkEvents>
  </soap:Body>
</soap:Envelope>

我现在有这个代码:

public static Object vrati_ds(String id, String name, String username, String password, String since, String to, String reg, String korisnik, String nalog, String nameString status, String value){
    try{
        SoapObject _client = new SoapObject(Konstante.NAMESPACE1, Konstante.METHOD_NAME);
        _client.addProperty("ID", id);
        _client.addProperty("Name", name);
        _client.addProperty("UserName", username);
        _client.addProperty("Password", password);
        _client.addProperty("Since", since);
        _client.addProperty("To", to);
        _client.addProperty("Reg", reg);
        _client.addProperty("Korisnik_app", korisnik);
        _client.addProperty("Nalog", nalog);
        _client.addProperty("Status", status);
        _client.addProperty("Value", value);
        SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        _envelope.dotNet = true;
        _envelope.setOutputSoapObject(_client);
        HttpTransportSE _ht = new HttpTransportSE(Konstante.URL1);
        _ht.call(Konstante.SOAP_ACTION, _envelope);
        return _envelope.getResponse();
    } catch(Exception e) {
        return null;
    }
}

如果有人可以帮助我,我提前感谢您!

4

4 回答 4

2

现在我手动硬编码 xml 请求,所以如果有人可以提供帮助,这里是有效的源代码:

public static Object getEvent2(int id, String name, String username, String password, String since, String to, 
        String reg, String nalog, String status, String value ) throws Exception {

    String response= null;
    String xml = null;

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(Konstante.URL);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.encodingStyle = SoapSerializationEnvelope.ENC;

    String bodyOut = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    bodyOut += "<soap:Body><"+Konstante.EVENS_METHOD_NAME+" xmlns=\"" + Konstante.NAMESPACE + "\">";
    bodyOut += "<User><ID>" + id + "</ID><Name>" + name + "</Name><UserName>";
    bodyOut += username + "</UserName><Password>" + password + "</Password></User>";
    bodyOut += "<Filter><TimeSpan><Since>" + since + "+02:00" + "</Since><To>" + to + "+02:00" +"</To></TimeSpan>";
    bodyOut += "<Reg>" + reg + "</Reg><Nalog>" + nalog + "</Nalog><Status>" + status + "</Status><Value>" + value + "</Value></Filter>";
    bodyOut += "</"+Konstante.EVENS_METHOD_NAME+"></soap:Body></soap:Envelope>";

    xml = bodyOut;

    StringEntity se = new StringEntity(xml, HTTP.UTF_8);
    se.setContentType("text/xml");
    httpPost.addHeader(Konstante.EVENS_SOAP_ACTION, Konstante.URL);
    httpPost.setEntity(se);

    HttpResponse httpResponse = httpClient.execute(httpPost);
    HttpEntity resEntity = httpResponse.getEntity();
    response = EntityUtils.toString(resEntity);

    return response;
}
于 2012-09-03T12:00:08.027 回答
1

我也遇到了同样的问题。似乎信封对 SOAP 长度有限制,不允许大于 500……不确定。

于 2015-04-23T08:10:03.713 回答
1

有点晚了,但这里有一个答案。基于此提示,您可以遵循一些示例。对于您的情况,我相信这应该有效:

    SoapObject request = new SoapObject(Konstante.NAMESPACE1, "GetQuickParkEvents");

SoapObject user = new SoapObject(Konstante.NAMESPACE1, "User");
user.addProperty("ID", "int");
user.addProperty("Name", "string");
user.addProperty("UserName", "UserName");
user.addProperty("Password", "Password");

SoapObject filter = new SoapObject(Konstante.NAMESPACE1, "Filter");

SoapObject timeSpan = new SoapObject(Konstante.NAMESPACE1, "TimeSpan");
timeSpan.addProperty("Since", "dateTime");
timeSpan.addProperty("To", "dateTime");

filter.addSoapObject(timeSpan);
filter.addProperty("Reg", "string");
filter.addProperty("Nalog", "string");
filter.addProperty("Status", "string");
filter.addProperty("Value", "string");


request.addSoapObject(user);
request.addSoapObject(filter);
于 2016-09-07T11:05:25.200 回答
0

这是 ksoap2 教程:

http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#sending/receiving_array_of_complex_types_or_primitives

如果您需要更具体的帮助,请发布您当前的代码。

于 2012-08-31T15:36:43.313 回答