我想通过使用ksoap2从andriod websevice程序中使用soap webservices。为此我写了以下代码。当我在Android模拟器中运行它时,我没有在我的logcat中获得响应。我的webservices返回类型结果是XML文件。
public class SoapWebservicesExampleActivity extends Activity {
/** Called when the activity is first created. */
final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
final String URL = "http://***********:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user=*******&sap-password=*********";
//i am appending the Username and password as URL Parameters.
final String METHOD_NAME = "Z_GET_CUST_GEN";
final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";
// i am getting the method name tns from WSDL file.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
request.addProperty("Input", "1460");
// request.addProperty("Langu", "d");
//one property in the webservices
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
// by using call method we can call the services
SoapObject response = (SoapObject)envelope.getResponse();
String str = response.getProperty(0).toString();
System.out.println("theeeeeeeeeee"+str);
//printing the respose here
}
catch(SocketException ex){
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
但问题是我得到了这个例外我正在添加ksoap2 jar文件。
05-29 15:37:54.403: WARN/System.err(383): 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:686 in java.io.InputStreamReader@40547218)
05-29 15:37:54.403: WARN/System.err(383): at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)
答案 0 :(得分:0)
这意味着您要添加的属性,即
request.addProperty("Input", "1460");
不合适。请检查您正在调用的Web方法,并确保参数的数量,方法名称,拼写(包括大小写)也是正确的。我一直都会遇到这个错误。这就是你解决它的方法。
((请分享您的网络方法。如果上述解决方案不起作用))
答案 1 :(得分:0)
<soap:Header/>
<soap:Body> <urn:Z_GET_CUST_GEN>
<!--Optional:-->
<Input>1460</Input>
<!--Optional:-->
<Langu>d</Langu>
<!--Optional:-->
<Max></Max>
这是我的输入和输出xml:
绑定网址
http://************:8000/sap/bc/srt/rfc/sap/z_customer_lookup1/800/z_customer_lookup1/z_customer_lookup1_bind
输出: -
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header/>
<env:Body>
<n0:Z_GET_CUST_GENResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<ZCustGen>
<item>
<Kunnr>0000001460</Kunnr>
<Name1>C.A.S. Computer Application Systems</Name1>
<City>Dresden</City>
<Land>DE</Land>
<Pstlz>01187</Pstlz>
</item>
<item>
<Kunnr>0000027182</Kunnr>
<Name1>Johnson Food Center Inc.</Name1>
<City>Rochester</City>
<Land>US</Land>
<Pstlz>14608</Pstlz>
</item>
<item>
<Kunnr>0000301046</Kunnr>
<Name1>Second Source</Name1>
<City>ROCHESTER</City>
<Land>US</Land>
<Pstlz>14602</Pstlz>
</item>
</ZCustGen>
</n0:Z_GET_CUST_GENResponse>
</env:Body>
</env:Envelope>
将输入设置为所有值(langu,max)并尝试。是否你尝试过。