gpt4 book ai didi

java - 将参数传递到 KSOAP2

转载 作者:太空宇宙 更新时间:2023-11-04 10:14:51 26 4
gpt4 key购买 nike

预先感谢您花点时间阅读此问题。我正在尝试使用 ksoap2 将 Android 应用程序与 SOAP Web 服务集成。

这是我想要提出的示例请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns="http://clients.mindbodyonline.com/api/0_5_1">
<soapenv:Header/>
<soapenv:Body>
<ValidateStaffLogin>
<Request>
<SourceCredentials>
<SourceName>JohnDoe</SourceName>
<Password>123ABCFAKEAPIKEY123</Password>
<SiteIDs>
<int>-99</int>
</SiteIDs>
</SourceCredentials>
<Username>Siteowner</Username>
<Password>apitest1234</Password>
</Request>
</ValidateStaffLogin>
</soapenv:Body>
</soapenv:Envelope>

这是 Web 服务 java 文件的 fragment :

public class WebService {
//Namespace of the Webservice - can be found in WSDL
private static String NAMESPACE =
"http://clients.mindbodyonline.com/api/0_5_1";
//Webservice URL - WSDL File location
private static String URL =
"https://api.mindbodyonline.com/0_5_1/StaffService.asmx";
//SOAP Action URI again Namespace + Web method name
private static String SOAP_ACTION =
"http://clients.mindbodyonline.com/api/0_5_1";

public static boolean invokeLoginWS(String userName,String passWord, String
webMethName) {
boolean loginStatus = false;
// Create request
SoapObject request = new SoapObject(NAMESPACE, webMethName);

request.addProperty("SourceCredentials", "SourceName", "JohnDoe");
request.addProperty("SourceCredentials", "Password",
"123ABCFAKEAPIKEY123");
request.addProperty("SourceCredentials", "SiteIDs", "-99");
request.addProperty("Username", "Siteowner");
request.addProperty("Password", "apitest1234");


// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to boolean variable variable
loginStatus = Boolean.parseBoolean(response.toString());

} catch (Exception e) {
//Assign Error Status true in static variable 'errored'
LoginActivity.errored = true;
e.printStackTrace();
}
//Return booleam to calling object
return loginStatus;
}
}

我的问题是我应该如何将不同的变量传递到两个单独的密码字段中。我找到了 ksoap2 方法 addProperty(namespace, name, value),但我不确定这是否是正确的方法。

此外,我对 NAMESPACE、URL 和 SOAP_ACTION 变量以及如何正确填写它们有些困惑。

最佳答案

    SoapObject request = new SoapObject(ApiUrl.NAMESPACE,
ApiUrl.METHODNAME_LOGIN);

SoapSerializationEnvelope soapenvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapenvelope.dotNet = true;
soapenvelope.bodyIn = false;

HttpTransportSE androidHttpTransport = new HttpTransportSE(
ApiUrl.DMATURL);
androidHttpTransport.debug = true;
soapenvelope.setAddAdornments(false);
androidHttpTransport
.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
// HttpTransportSE transport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(ApiUrl.SOAPACTION_LOGIN, soapenvelope);
String responss = androidHttpTransport.responseDump;

//System.out.println("request==" +androidHttpTransport.requestDump);
// System.out.println("responss===" + responss);

SoapObject resultRequestSOAP = (SoapObject) soapenvelope
.getResponse();
SoapObject response = (SoapObject) soapenvelope.bodyIn;
}
catch(Exception ex){
ex.printStackTrace();
}

关于java - 将参数传递到 KSOAP2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51847752/

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