我是新手,使用KSOAP2与Android和我有aproblem
我看过有关同一问题的类似帖子,但没有人帮我解决错误
我正在尝试连接到返回我登录的用户名的Web服务(WSDL)。 当我在任何浏览器中打开Web服务URL时,它首先要求输入用户名和密码,然后将该用户名返回给我,在代码中我不知道如何发送此用户名和密码。我也想要帮助
下面是我的代码:
package com.example.webservicetest;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
public class AndroidWSClientActivity extends Activity {
static final int CONNECTING_PROGRESS_DIALOG = 0;
private static final String TAG = "MeGetCurrentUserId";
private static final String WSDL_URL = "http://IP:8010/sap/bc/srt/wsdl/srvc_000C293D85161ED39484844BDA759A86/wsdl11/allinone/ws_policy/document?sap-client=200&sap-user=*********&sap-password=********";
private static final String WS_NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
private static final String WS_METHOD_NAME = "MeGetCurrentUserId";
private static final String soapAction = "urn:sap-com:document:sap:soap:functions:mc-style:ZUSER_ID:MeGetCurrentUserIdRequest";//"urn:sap-com:document:sap:soap:functions:mc-style:ZME_GET_CURRENT_USER_ID3:MeGetCurrentUserIdRequest";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_wsclient);
new GetUserNameTask().execute();
}
private String parseSOAPResponse(SoapObject response) {
String result = null;
SoapObject usernameResult = (SoapObject) response
.getProperty("MeGetCurrentUserIdResponse");
if (usernameResult != null) {
for (int i = 0; i < usernameResult .getPropertyCount(); i++) {
SoapObject unameDescription = (SoapObject) usernameResult
.getProperty(i);
String Username = unameDescription
.getPrimitivePropertySafelyAsString("Username");
Log.i(TAG, Username);
result = Username;
}
}
return result;
}
private class GetUserNameTask extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
showDialog(CONNECTING_PROGRESS_DIALOG);
}
@Override
protected String doInBackground(Void... params) {
String result=null;
final String str = null;
try {
SoapObject request = new SoapObject(WS_NAMESPACE, WS_METHOD_NAME);
MarshalBase64 mbase = new MarshalBase64();
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(WSDL_URL);
mbase.register(envelope);
androidHttpTransport.call(soapAction, envelope);
Log.d(TAG, "HTTP REQUEST:\n" + androidHttpTransport.requestDump);
Log.d(TAG, "HTTP RESPONSE:\n" + androidHttpTransport.responseDump);
final SoapPrimitive resp = (SoapPrimitive)envelope.getResponse();
Log.d(TAG, "HTTP resp:\n" + resp);
Object resonse=envelope.getResponse();
String output = resonse.toString();
if (envelope.bodyIn instanceof SoapObject) { // SoapObject = SUCCESS
SoapObject soapObject = (SoapObject) envelope.bodyIn;
result = parseSOAPResponse(soapObject);
Log.v("result", "result = "+result);
} else if (envelope.bodyIn instanceof SoapFault) { // SoapFault = // FAILURE
SoapFault soapFault = (SoapFault) envelope.bodyIn;
try {
throw new Exception(soapFault.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
@Override
protected void onPostExecute(String response) {
removeDialog(CONNECTING_PROGRESS_DIALOG);
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case CONNECTING_PROGRESS_DIALOG: {
ProgressDialog loadingDialog = new ProgressDialog(this);
loadingDialog.setMessage("Connecting");
loadingDialog.setIndeterminate(true);
loadingDialog.setCancelable(false);
return loadingDialog;
}
}
return null;
}
}
我收到以下错误:
11-19 15:30:46.520: W/System.err(29600): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions targetNamespace='urn:sap-com:document:sap:soap:functions:mc-style'>@1:687 in java.io.InputStreamReader@408e2840)
11-19 15:30:46.520: W/System.err(29600): at org.kxml2.io.KXmlParser.require(KXmlParser.java:2037)
11-19 15:30:46.520: W/System.err(29600): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:128)
11-19 15:30:46.520: W/System.err(29600): at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
11-19 15:30:46.520: W/System.err(29600): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:197)
11-19 15:30:46.520: W/System.err(29600): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
11-19 15:30:46.520: W/System.err(29600): at com.example.webservicetest.AndroidWSClientActivity$GetUserNameTask.doInBackground(AndroidWSClientActivity.java:95)
11-19 15:30:46.520: W/System.err(29600): at com.example.webservicetest.AndroidWSClientActivity$GetUserNameTask.doInBackground(AndroidWSClientActivity.java:1)
11-19 15:30:46.520: W/System.err(29600): at android.os.AsyncTask$2.call(AsyncTask.java:252)
11-19 15:30:46.520: W/System.err(29600): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-19 15:30:46.520: W/System.err(29600): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-19 15:30:46.520: W/System.err(29600): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
11-19 15:30:46.520: W/System.err(29600): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
11-19 15:30:46.520: W/System.err(29600): at java.lang.Thread.run(Thread.java:1020)
错误在这一行
httpTransport.call(soapAction, envelope);
这是我的WSDL
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="urn:sap-com:document:sap:soap:functions:mc-style" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:n1="urn:sap-com:document:sap:rfc:functions" targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style">
<wsdl:documentation>
<sidl:sidl xmlns:sidl="http://www.sap.com/2007/03/sidl"/>
</wsdl:documentation>
<wsp:UsingPolicy wsdl:required="true"/>
<wsp:Policy wsu:Id="BN_BN_ZME_GET_CURRENT_USER_ID">
<saptrnbnd:OptimizedXMLTransfer xmlns:saptrnbnd="http://www.sap.com/webas/710/soap/features/transportbinding/" uri="http://xml.sap.com/2006/11/esi/esp/binxml" wsp:Optional="true"/>
<saptrnbnd:OptimizedMimeSerialization xmlns:saptrnbnd="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" wsp:Optional="true"/>
<wsp:ExactlyOne xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:All>
<sp:TransportBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sapsp="http://www.sap.com/webas/630/soap/features/security/policy" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken>
<wsp:Policy>
<sp:HttpBasicAuthentication/>
</wsp:Policy>
</sp:HttpsToken>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic128Rsa15/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
<wsaw:UsingAddressing xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" wsp:Optional="true"/>
</wsp:Policy>
<wsp:Policy wsu:Id="BN_BN_ZME_GET_CURRENT_USER_ID_SOAP12">
<saptrnbnd:OptimizedXMLTransfer xmlns:saptrnbnd="http://www.sap.com/webas/710/soap/features/transportbinding/" uri="http://xml.sap.com/2006/11/esi/esp/binxml" wsp:Optional="true"/>
<saptrnbnd:OptimizedMimeSerialization xmlns:saptrnbnd="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" wsp:Optional="true"/>
<wsp:ExactlyOne xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:All>
<sp:TransportBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sapsp="http://www.sap.com/webas/630/soap/features/security/policy" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken>
<wsp:Policy>
<sp:HttpBasicAuthentication/>
</wsp:Policy>
</sp:HttpsToken>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic128Rsa15/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
<wsaw:UsingAddressing xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" wsp:Optional="true"/>
</wsp:Policy>
<wsp:Policy wsu:Id="IF_IF_zME_GET_CURRENT_USER_ID">
<sapsession:Session xmlns:sapsession="http://www.sap.com/webas/630/soap/features/session/">
<sapsession:enableSession>false</sapsession:enableSession>
</sapsession:Session>
<sapcentraladmin:CentralAdministration xmlns:sapcentraladmin="http://www.sap.com/webas/700/soap/features/CentralAdministration/" wsp:Optional="true">
<sapcentraladmin:BusinessApplicationID>000C293D85161EE392C16B764ABA0F3C</sapcentraladmin:BusinessApplicationID>
</sapcentraladmin:CentralAdministration>
</wsp:Policy>
<wsp:Policy wsu:Id="OP_IF_OP_MeGetCurrentUserId">
<sapcomhnd:enableCommit xmlns:sapcomhnd="http://www.sap.com/NW05/soap/features/commit/">false</sapcomhnd:enableCommit>
<sapblock:enableBlocking xmlns:sapblock="http://www.sap.com/NW05/soap/features/blocking/">true</sapblock:enableBlocking>
<saptrhnw05:required xmlns:saptrhnw05="http://www.sap.com/NW05/soap/features/transaction/">no</saptrhnw05:required>
<saprmnw05:enableWSRM xmlns:saprmnw05="http://www.sap.com/NW05/soap/features/wsrm/">false</saprmnw05:enableWSRM>
</wsp:Policy>
<wsdl:types>
<xsd:schema attributeFormDefault="qualified" targetNamespace="urn:sap-com:document:sap:rfc:functions">
<xsd:simpleType name="char12">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="12"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<xsd:schema xmlns:n0="urn:sap-com:document:sap:rfc:functions" attributeFormDefault="qualified" targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style">
<xsd:import namespace="urn:sap-com:document:sap:rfc:functions"/>
<xsd:element name="MeGetCurrentUserId">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="MeGetCurrentUserIdResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Username" type="n0:char12"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="MeGetCurrentUserId">
<wsdl:part name="parameters" element="tns:MeGetCurrentUserId"/>
</wsdl:message>
<wsdl:message name="MeGetCurrentUserIdResponse">
<wsdl:part name="parameter" element="tns:MeGetCurrentUserIdResponse"/>
</wsdl:message>
<wsdl:portType name="zME_GET_CURRENT_USER_ID">
<wsdl:documentation>
<sapdoc:sapdoc xmlns:sapdoc="urn:sap:esi:documentation">
<sapdoc:docitem docURL="http://edr-aioexp.edraky.local:8010/sap/bc/esdt/docu/sd_text?sap-client=200&sd_name=ZME_GET_CURRENT_USER_ID"/>
</sapdoc:sapdoc>
</wsdl:documentation>
<wsp:Policy>
<wsp:PolicyReference URI="#IF_IF_zME_GET_CURRENT_USER_ID"/>
</wsp:Policy>
<wsdl:operation name="MeGetCurrentUserId">
<wsp:Policy>
<wsp:PolicyReference URI="#OP_IF_OP_MeGetCurrentUserId"/>
</wsp:Policy>
<wsdl:input message="tns:MeGetCurrentUserId"/>
<wsdl:output message="tns:MeGetCurrentUserIdResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ZME_GET_CURRENT_USER_ID" type="tns:zME_GET_CURRENT_USER_ID">
<wsp:Policy>
<wsp:PolicyReference URI="#BN_BN_ZME_GET_CURRENT_USER_ID"/>
</wsp:Policy>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="MeGetCurrentUserId">
<soap:operation soapAction="urn:sap-com:document:sap:soap:functions:mc-style:zME_GET_CURRENT_USER_ID:MeGetCurrentUserIdRequest" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ZME_GET_CURRENT_USER_ID_SOAP12" type="tns:zME_GET_CURRENT_USER_ID">
<wsp:Policy>
<wsp:PolicyReference URI="#BN_BN_ZME_GET_CURRENT_USER_ID_SOAP12"/>
</wsp:Policy>
<wsoap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="MeGetCurrentUserId">
<wsoap12:operation soapAction="urn:sap-com:document:sap:soap:functions:mc-style:zME_GET_CURRENT_USER_ID:MeGetCurrentUserIdRequest" style="document"/>
<wsdl:input>
<wsoap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<wsoap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ZME_GET_CURRENT_USER_ID">
<wsdl:port name="ZME_GET_CURRENT_USER_ID" binding="tns:ZME_GET_CURRENT_USER_ID">
<soap:address location="http://edr-aioexp.edraky.local:8010/sap/bc/srt/rfc/sap/zme_get_current_user_id/200/zme_get_current_user_id/zme_get_current_user_id"/>
</wsdl:port>
<wsdl:port name="ZME_GET_CURRENT_USER_ID_SOAP12" binding="tns:ZME_GET_CURRENT_USER_ID_SOAP12">
<wsoap12:address location="http://edr-aioexp.edraky.local:8010/sap/bc/srt/rfc/sap/zme_get_current_user_id/200/zme_get_current_user_id/zme_get_current_user_id"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
知道我们已将IP edr-aioexp.edraky.local
映射到我在网址中使用的真实IP
有人可以帮我吗?
修改
我没有收到ANDROID的回复,
这个Web服务存在于SAP系统上。当在SAP系统上测试时,会出现此响应,但在android上我没有收到任何响应。
REQUEST
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<sapsess:Session xmlns:sapsess="http://www.sap.com/webas/630/soap/features/session/">
<enableSession>true</enableSession>
</sapsess:Session>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:MeGetCurrentUserId xmlns:ns1='urn:sap-com:document:sap:soap:functions:mc-style'>
</ns1:MeGetCurrentUserId>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
RESPONSE
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header/>
<soap-env:Body>
<n0:MeGetCurrentUserIdResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<Username>EAB_SAMIR</Username>
</n0:MeGetCurrentUserIdResponse>
</soap-env:Body>
</soap-env:Envelope>
答案 0 :(得分:2)
您有错误
org.xmlpull.v1.XmlPullParserException: expected: START_TAG
这意味着您可能在以下一个(或多个)中出现错误:WSDL_URL,WS_NAMESPACE,WS_METHOD_NAME,。
尝试推杆:
WS_NAMESPACE="urn:sap-com:document:sap:soap:functions:mc-style"
soapAction= "zME_GET_CURRENT_USER_ID"
你还得到那个错误吗?
答案 1 :(得分:1)
这篇文章XmlPullParserException when using SAP WSDL WebService
帮助我解决了我的问题
我的问题出在soapAction
和WSDL_URL
我在WSDL文件中使用了URL而不是我在浏览器中编写的URL:找到下面的编写代码
private static final String soapAction = WS_NAMESPACE + "/" + WS_METHOD_NAME;
private static final String WSDL_URL = "http://IP:8010/sap/bc/srt/rfc/sap/zme_get_current_user_id3/200/zme_get_current_user_id3/zme_get_current_user_id3?sap-user=******&sap-password=******";
我得到了正确答案。
非常感谢大家帮我解决问题
答案 2 :(得分:0)
check this you have to use request.addProperty() for sending parameter
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
request.addProperty("User Name", MYUSERNAME);
request.addProperty("username", MYUSERNAME);
request.addProperty("Password", MYPASSWORD);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object resonse=envelope.getResponse();
String output = resonse.toString();