是新來這個SOAP的Web服務。這是我的KSOAP LIB扶養,如何在Android中進行SOAP解析?
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}
dependencies {
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
}
請看看我的SOAP請求和響應
POST /loyaltywebservice/LoyaltyWebService.asmx HTTP/1.1
Host: host url is here
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/AttemptLogin"
<?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:Header>
<UserCredential xmlns="http://tempuri.org/">
<userName>string</userName>
<password>string</password>
</UserCredential>
</soap:Header>
<soap:Body>
<AttemptLogin xmlns="http://tempuri.org/">
<LoyalCustCode>string</LoyalCustCode>
<PwdStr>string</PwdStr>
</AttemptLogin>
</soap:Body>
</soap:Envelope>
雖然上午解析正在逐漸網絡服務身份驗證失敗。但是這是在「POSTMAN」中工作的。下面的代碼我已經嘗試過了,並且我剛更改的用戶名和密碼,因爲我無法打開證書。所以我只是添加了1234.看看我的代碼。並請幫助我在哪裏做錯了。
public void soapLogin() {
try {
new Thread(new Runnable() {
@Override
public void run() {
try {
//Prepare the header with the authentication data.
Element headers = new Element().createElement(UrlActivity.NAMESPACE, "UserCredential");
Element username = new Element().createElement(UrlActivity.NAMESPACE, "userName");
username.addChild(Node.TEXT, "test");
headers.addChild(Node.ELEMENT, username);
Element pass = new Element().createElement(UrlActivity.NAMESPACE, "password");
pass.addChild(Node.TEXT, "1234");
headers.addChild(Node.ELEMENT, pass);
// Soap Request
final SoapObject request = new SoapObject(UrlActivity.NAMESPACE, UrlActivity.METHOD_NAME);
request.addProperty("LoyalCustCode","12345");
request.addProperty("PwdStr","12345");
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// add header to envelope
envelope.headerOut = new Element[1];
envelope.headerOut[0] = headers;
envelope.setOutputSoapObject(request);
//Add the header to the envelope.
final HttpTransportSE androidHttpTransport = new HttpTransportSE(UrlActivity.URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(UrlActivity.SOAP_ACTION, envelope);
Log.d("Login", "Request:- "+androidHttpTransport.requestDump);
final SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
Log.d("Login", "Response:- "+androidHttpTransport.responseDump);
// final SoapObject result = (SoapObject) envelope.getResponse();
String response = result.toString();
Log.d("Login", "Response:- "+response);
}catch (Exception ex){
Log.e("Login", "soapLogin:- "+ex.getMessage());
}
}
}).start();
} catch (Exception e) {
e.printStackTrace();
}
}
什麼樣的錯誤?您分享錯誤日誌 – Ninja
soapcliente我/ resultado ::函數嘗試登錄錯誤:-2147467261 –
請發佈您日誌,因爲在一行lo g不容易確切知道問題出在哪裏(Androin或PHP)? – Ninja