您好我有一个代码,用于生成对示例soap服务器的简单请求,我需要构建一个请求,如:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://10.1.5.80:8080/">
<soapenv:Header/>
<soapenv:Body>
<ns:GETSERVERTIME/>
</soapenv:Body>
</soapenv:Envelope>
但是我得到了
<v:Envelope
xmlns:i="http://www.w3.org/1999/XMLSchema-instance"
xmlns:d="http://www.w3.org/1999/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<n0:GETSERVERTIME xmlns:n0="http://localhost:8080/" />
</v:Body>
</v:Envelope>
我只需要改变&#34; v:&#34; to&#34; soapenv:&#34;
我的代码:
/**
* Created by Vinicius Gati on 30/12/14.
*
*/
public class ServerSOAP {
private static final String METHOD_NAME = "GETSERVERTIME";
private static final String NAMESPACE = "http://localhost:8080/";
private static final String SOAP_ACTION = "";
private static final String URL = "http://10.1.5.80:8080/ws/SERVERTIME.apw?WSDL";
public static String getServerTime() {
String retorno = "";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.implicitTypes = false;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call( NAMESPACE + METHOD_NAME, envelope );
SoapObject response = (SoapObject) envelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
}
return retorno;
}
}
但是我很难尝试,但没有成功。
答案 0 :(得分:1)
write方法将前缀定义为字符串常量(来自SoapEnvelope类的代码副本,请参阅提供的链接):
public void write(XmlSerializer writer) throws IOException {
writer.setPrefix("i", xsi);
writer.setPrefix("d", xsd);
writer.setPrefix("c", enc);
writer.setPrefix("v", env);
writer.startTag(env, "Envelope");
writer.startTag(env, "Header");
writeHeader(writer);
writer.endTag(env, "Header");
writer.startTag(env, "Body");
writeBody(writer);
writer.endTag(env, "Body");
writer.endTag(env, "Envelope");
}
因此,您可以尝试定义自己的类,继承自SoapSerializationEnvelope并尝试重新定义此方法以使用&#34; soapenv&#34;前缀。
BTW:如果WS无法读取任何名称的前缀,则该服务端的代码很差。 &#34; soapenv&#34;或&#34; v&#34;在xml&#39; s中你应该被解释为相同。
的Marcin
答案 1 :(得分:0)
哥们,
我已经解决了这个问题。实际上我已经扩展了SoapSerializationEnvelope
类并覆盖了SoapSerializationEnvelope
的{{1}}方法,如下所示
write()