gpt4 book ai didi

java - ksoap2 v prefixo 到任何其他前缀

转载 作者:行者123 更新时间:2023-11-30 08:58:22 25 4
gpt4 key购买 nike

您好,我有一个代码可以生成一个简单的请求到一个示例 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>

我只需要将“v:”改为“soapenv:”

我的代码:

/**
* 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;
}

}

但我很疯狂地尝试这个,但没有成功。

最佳答案

如您所见: https://github.com/mosabua/ksoap2-android/blob/master/ksoap2-base/src/main/java/org/ksoap2/SoapEnvelope.java

编写方法将前缀定义为字符串常量(从类 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 并尝试重新定义此方法以使用“soapenv”前缀。

顺便说一句:如果 WS 无法读取任何名称的前缀,则说明此服务端的代码很糟糕。 “soapenv”或“v”在包含的两个 xml 中应被解释为相同。

马辛

关于java - ksoap2 v prefixo 到任何其他前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27710169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com