我正在使用 KSoap2 访问 SAP Web 服务。
下面是我的代码
package com.example.getcustomerwsdl;
public class GetCustomerActivity extends Activity {
static final int CONNECTING_PROGRESS_DIALOG = 0;
private static final String TAG = "SdRfcCustomerGet";
private static final String WS_NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
private static final String WS_METHOD_NAME = "SdRfcCustomerGet";
private static final String soapAction = WS_NAMESPACE + "/"+ WS_METHOD_NAME;
private static final String WSDL_URL = "http://IP:8010/sap/bc/srt/rfc/sap/zcustomer_get2/200/zcustomer_get2/zcustomer_get2?sap-user=*******&sap-password=*******";
String result = null;
TextView responseTxtView;
ItemObject C;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_customer);
responseTxtView = (TextView) findViewById(R.id.textview1);
new GetUCustomerTask().execute();
}
private class GetUCustomerTask extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
showDialog(CONNECTING_PROGRESS_DIALOG);
}
@Override
protected String doInBackground(Void... params) {
final String str = null;
String output = null;
AndroidHttpTransport androidHttpTransport = null;
try {
SoapObject request = new SoapObject(WS_NAMESPACE,
WS_METHOD_NAME);
ItemObject items = new ItemObject();
items = new ItemObject("","","","","","","","","");
CustomerObject custT = new CustomerObject(items);
custT.item = items;
PropertyInfo pinfoCustomer = new PropertyInfo();
pinfoCustomer.setName("CustomerT");
pinfoCustomer.setValue(custT);
pinfoCustomer.setType(custT.getClass());
request.addProperty(pinfoCustomer);
PropertyInfo pi = new PropertyInfo();
pi.setName("Kunnr");
pi.setValue("0000491100");
pi.setType(String.class);
request.addProperty(pi);
PropertyInfo pi3 = new PropertyInfo();
pi3.setName("Name1");
pi3.setValue("");
pi3.setType(String.class);
request.addProperty(pi3);
MarshalBase64 mbase = new MarshalBase64();
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.encodingStyle = SoapSerializationEnvelope.ENV;
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(WS_NAMESPACE, "CustomerT",new CustomerObject().getClass());
androidHttpTransport = new AndroidHttpTransport(WSDL_URL);
androidHttpTransport.debug = true;
mbase.register(envelope);
androidHttpTransport.call(soapAction, envelope);
Log.d(TAG, "HTTP REQUEST1:\n"
+ androidHttpTransport.requestDump);
Log.d(TAG, "HTTP RESPONSE1:\n"
+ androidHttpTransport.responseDump);
if (envelope.bodyIn instanceof SoapFault) {
String strn= ((SoapFault) envelope.bodyIn).faultstring;
Log.i("SoapFault", strn);
} else {
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Log.d("WS", String.valueOf(resultsRequestSOAP));
}
SoapObject response = (SoapObject) envelope.getResponse();
C.Kunnr = response.getProperty(0)
.toString();
C.Anred = response.getProperty(1).toString();
C.Name1 = (String) response.getProperty(2).toString();
C.Pfach = (String) response.getProperty(3).toString();
C.Stras = (String) response.getProperty(4).toString();
C.Pstlz = (String) response.getProperty(5).toString();
C.Telf1 = (String) response.getProperty(6).toString();
C.Telfx = (String) response.getProperty(7).toString();
C.Ort01 = (String) response.getProperty(8).toString();
Log.d(TAG, "HTTP response:\n" + response);
final SoapPrimitive resp = (SoapPrimitive) envelope
.getResponse();
Log.d(TAG, "HTTP resp:\n" + resp);
SoapObject resonse = (SoapObject) envelope.getResponse();
output = resonse.toString();
Log.d(TAG, "HTTP REQUEST2:\n"
+ androidHttpTransport.requestDump);
Log.d(TAG, "HTTP RESPONSE2:\n"
+ androidHttpTransport.responseDump);
Log.d(TAG, "output:\n" + resonse.getProperty(0).toString());
result = output;
if (envelope.bodyIn instanceof SoapObject) { // SoapObject =
// SUCCESS
SoapObject soapObject = (SoapObject) envelope.bodyIn;
} else if (envelope.bodyIn instanceof SoapFault) {
SoapFault soapFault = (SoapFault) envelope.bodyIn;
try {
soapFault.getMessage();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("HTTP REQUESTEXP:\n"
+ androidHttpTransport.requestDump);
System.out.println("HTTP RESPONSEEXP:\n"
+ androidHttpTransport.responseDump);
}
return result;
}
@Override
protected void onPostExecute(final String response) {
removeDialog(CONNECTING_PROGRESS_DIALOG);
runOnUiThread(new Runnable() {
public void run() {
responseTxtView.setText("response " + result);
Toast.makeText(getApplicationContext(),
"response" + result, Toast.LENGTH_LONG).show();
}
});
}
}
@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;
}
}
客户对象类
package com.example.getcustomerwsdl;
public class CustomerObject implements KvmSerializable {
ItemObject item;
public CustomerObject() {
}
public CustomerObject(ItemObject item) {
super();
this.item = item;
}
public ItemObject getItem() {
return item;
}
public void setItem(ItemObject item) {
this.item = item;
}
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
switch (arg0) {
case 0:
return item;
}
return null;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 1;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
// TODO Auto-generated method stub
switch (index) {
case 0:
info.type = ItemObject.class;
info.name = "item";
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
// TODO Auto-generated method stub
switch (index) {
case 0:
item = (ItemObject) value;
break;
default:
break;
}
}
}
项目对象类
package com.example.getcustomerwsdl;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class ItemObject implements KvmSerializable {
String Kunnr;
String Anred;
String Name1;
String Pfach;
String Stras;
String Pstlz;
String Telf1;
String Telfx;
String Ort01;
public ItemObject() {
super();
}
public ItemObject(String kunnr, String anred, String name1,
String pfach, String stras, String pstlz, String telf1,
String telfx, String ort01) {
super();
Kunnr = kunnr;
Anred = anred;
Name1 = name1;
Pfach = pfach;
Stras = stras;
Pstlz = pstlz;
Telf1 = telf1;
Telfx = telfx;
Ort01 = ort01;
}
public String getKunnr() {
return Kunnr;
}
public void setKunnr(String kunnr) {
Kunnr = kunnr;
}
public String getAnred() {
return Anred;
}
public void setAnred(String anred) {
Anred = anred;
}
public String getName1() {
return Name1;
}
public void setName1(String name1) {
Name1 = name1;
}
public String getPfach() {
return Pfach;
}
public void setPfach(String pfach) {
Pfach = pfach;
}
public String getStras() {
return Stras;
}
public void setStras(String stras) {
Stras = stras;
}
public String getPstlz() {
return Pstlz;
}
public void setPstlz(String pstlz) {
Pstlz = pstlz;
}
public String getTelf1() {
return Telf1;
}
public void setTelf1(String telf1) {
Telf1 = telf1;
}
public String getTelfx() {
return Telfx;
}
public void setTelfx(String telfx) {
Telfx = telfx;
}
public String getOrt01() {
return Ort01;
}
public void setOrt01(String ort01) {
Ort01 = ort01;
}
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
switch (arg0) {
case 0:
return Kunnr;
case 1:
return Anred;
case 2:
return Name1;
case 3:
return Pfach;
case 4:
return Stras;
case 5:
return Pstlz;
case 6:
return Telf1;
case 7:
return Telfx;
case 8:
return Ort01;
}
return null;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 9;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
// TODO Auto-generated method stub
switch (index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Kunnr";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Anred";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Name1";
break;
case 3:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Pfach";
break;
case 4:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Stras";
break;
case 5:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Pstlz";
break;
case 6:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Telf1";
break;
case 7:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Telfx";
break;
case 8:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Ort01";
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
// TODO Auto-generated method stub
switch (index) {
case 0:
Kunnr = value.toString();
break;
case 1:
Anred = value.toString();
break;
case 2:
Name1 = value.toString();
break;
case 3:
Pfach = value.toString();
break;
case 4:
Stras = value.toString();
break;
case 5:
Pstlz = value.toString();
break;
case 6:
Telf1 = value.toString();
break;
case 7:
Telfx = value.toString();
break;
case 8:
Ort01 = value.toString();
break;
default:
break;
}
}
}
以下是我的目标请求
<?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:SdRfcCustomerGet xmlns:ns1='urn:sap-com:document:sap:soap:functions:mc-style'>
<CustomerT>
<item>
<Kunnr></Kunnr>
<Anred></Anred>
<Name1></Name1>
<Pfach></Pfach>
<Stras></Stras>
<Pstlz></Pstlz>
<Ort01></Ort01>
<Telf1></Telf1>
<Telfx></Telfx>
</item>
</CustomerT>
<Kunnr>0000491100</Kunnr>
<Name1></Name1>
</ns1:SdRfcCustomerGet>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我的目标回应
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header/>
<soap-env:Body>
<n0:SdRfcCustomerGetResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<CustomerT>
<item>
<Kunnr>0000491100</Kunnr>
<Anred/>
<Name1>Customer Company 02</Name1>
<Pfach>127 353</Pfach>
<Stras>Sheikh Zayed Road</Stras>
<Pstlz/>
<Ort01>Berlin</Ort01>
<Telf1/>
<Telfx/>
</item>
</CustomerT>
</n0:SdRfcCustomerGetResponse>
</soap-env:Body>
</soap-env:Envelope>
我收到以下错误
11-27 14:30:38.290: I/SoapFault(24418): Processing Error. More details in WS Error Log (transaction SRT_UTIL) by selection with UTC timestamp 20131127102016
11-27 14:30:38.310: W/System.err(24418): SoapFault - faultcode: 'soap-env:Server' faultstring: 'Processing Error. More details in WS Error Log (transaction SRT_UTIL) by selection with UTC timestamp 20131127102016 ' faultactor: 'null' detail: org.kxml2.kdom.Node@42b68288
11-27 14:30:38.310: W/System.err(24418): at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:112)
11-27 14:30:38.310: W/System.err(24418): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)
11-27 14:30:38.310: W/System.err(24418): at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
11-27 14:30:38.315: W/System.err(24418): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
11-27 14:30:38.315: W/System.err(24418): at com.example.getcustomerwsdl.GetCustomerActivity$GetUCustomerTask.doInBackground(GetCustomerActivity.java:130)
11-27 14:30:38.315: W/System.err(24418): at com.example.getcustomerwsdl.GetCustomerActivity$GetUCustomerTask.doInBackground(GetCustomerActivity.java:1)
11-27 14:30:38.315: W/System.err(24418): at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-27 14:30:38.315: W/System.err(24418): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-27 14:30:38.315: W/System.err(24418): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-27 14:30:38.315: W/System.err(24418): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-27 14:30:38.315: W/System.err(24418): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-27 14:30:38.315: W/System.err(24418): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-27 14:30:38.315: W/System.err(24418): at java.lang.Thread.run(Thread.java:856)
这是从我的代码发送到网络服务的请求
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<SdRfcCustomerGet xmlns="urn:sap-com:document:sap:soap:functions:mc-style" id="o0" c:root="1">
<CustomerT>
<item>
<Kunnr></Kunnr>
<Anred></Anred>
<Name1></Name1>
<Pfach></Pfach>
<Stras></Stras>
<Pstlz></Pstlz>
<Telf1></Telf1>
<Telfx></Telfx>
<Ort01></Ort01>
</item>
</CustomerT>
<Kunnr>0000491100</Kunnr>
<Name1></Name1>
</SdRfcCustomerGet>
</v:Body>
</v:Envelope>
这是我得到的回应
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header/>
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Server</faultcode>
<faultstring xml:lang="en">
Processing Error. More details in WS Error Log (transaction SRT_UTIL) by selection with UTC timestamp 20131127102016
</faultstring>
<detail/>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>
这是我的 WSDL 文件
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style" 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">
<wsdl:documentation>
<sidl:sidl xmlns:sidl="http://www.sap.com/2007/03/sidl"/>
</wsdl:documentation>
<wsp:UsingPolicy wsdl:required="true"/>
<wsp:Policy wsu:Id="IF_IF_ZCUSTOMER_GET2">
<sapsession:Session xmlns:sapsession="http://www.sap.com/webas/630/soap/features/session/">
<sapsession:enableSession>false</sapsession:enableSession>
</sapsession:Session>
</wsp:Policy>
<wsp:Policy wsu:Id="OP_IF_OP_SdRfcCustomerGet">
<sapblock:enableBlocking xmlns:sapblock="http://www.sap.com/NW05/soap/features/blocking/">true</sapblock:enableBlocking>
<sapcomhnd:enableCommit xmlns:sapcomhnd="http://www.sap.com/NW05/soap/features/commit/">false</sapcomhnd:enableCommit>
<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="char10">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="10"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char15">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="15"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char16">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="16"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char31">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="31"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char35">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="35"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<xsd:schema attributeFormDefault="qualified" targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style" xmlns:n0="urn:sap-com:document:sap:rfc:functions">
<xsd:import namespace="urn:sap-com:document:sap:rfc:functions"/>
<xsd:simpleType name="RfcException.Message.Number">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="3"/>
<xsd:pattern value="\d*"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Rfccust">
<xsd:sequence>
<xsd:element name="Kunnr" type="n0:char10"/>
<xsd:element name="Anred" type="n0:char15"/>
<xsd:element name="Name1" type="n0:char35"/>
<xsd:element name="Pfach" type="n0:char10"/>
<xsd:element name="Stras" type="n0:char35"/>
<xsd:element name="Pstlz" type="n0:char10"/>
<xsd:element name="Ort01" type="n0:char35"/>
<xsd:element name="Telf1" type="n0:char16"/>
<xsd:element name="Telfx" type="n0:char31"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="RfcException.Message">
<xsd:sequence>
<xsd:element name="ID" type="xsd:string"/>
<xsd:element name="Number" type="tns:RfcException.Message.Number"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="SdRfcCustomerGet.RfcException">
<xsd:sequence>
<xsd:element name="Name" type="tns:SdRfcCustomerGet.RfcExceptions"/>
<xsd:element name="Text" type="xsd:string" minOccurs="0"/>
<xsd:element name="Message" type="tns:RfcException.Message" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TableOfRfccust">
<xsd:sequence>
<xsd:element name="item" type="tns:Rfccust" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="SdRfcCustomerGet.RfcExceptions">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="NothingSpecified"/>
<xsd:enumeration value="NoRecordFound"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="SdRfcCustomerGet.Exception" type="tns:SdRfcCustomerGet.RfcException"/>
<xsd:element name="SdRfcCustomerGet">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CustomerT" type="tns:TableOfRfccust"/>
<xsd:element name="Kunnr" type="n0:char10" minOccurs="0"/>
<xsd:element name="Name1" type="n0:char35" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="SdRfcCustomerGetResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CustomerT" type="tns:TableOfRfccust"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="SdRfcCustomerGet">
<wsdl:part name="parameters" element="tns:SdRfcCustomerGet"/>
</wsdl:message>
<wsdl:message name="SdRfcCustomerGetResponse">
<wsdl:part name="parameter" element="tns:SdRfcCustomerGetResponse"/>
</wsdl:message>
<wsdl:message name="SdRfcCustomerGet.Exception">
<wsdl:part name="SdRfcCustomerGet.Exception" element="tns:SdRfcCustomerGet.Exception"/>
</wsdl:message>
<wsdl:portType name="ZCUSTOMER_GET2">
<wsdl:documentation>
<sapdoc:sapdoc xmlns:sapdoc="urn:sap:esi:documentation">
<sapdoc:docitem docURL="http://IP:8010/sap/bc/esdt/docu/sd_text?sap-client=200&sd_name=ZCUSTOMER_GET2"/>
</sapdoc:sapdoc>
</wsdl:documentation>
<wsp:Policy>
<wsp:PolicyReference URI="#IF_IF_ZCUSTOMER_GET2"/>
</wsp:Policy>
<wsdl:operation name="SdRfcCustomerGet">
<wsp:Policy>
<wsp:PolicyReference URI="#OP_IF_OP_SdRfcCustomerGet"/>
</wsp:Policy>
<wsdl:input message="tns:SdRfcCustomerGet"/>
<wsdl:output message="tns:SdRfcCustomerGetResponse"/>
<wsdl:fault name="SdRfcCustomerGet.Exception" message="tns:SdRfcCustomerGet.Exception"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
我不知道为什么我没有得到网络服务的响应......有人可以帮我吗?