以下解决方案经过测试并用于WCF 网络服务
如果你得到这个error
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>
@1:7 in java.io.InputStreamReader@41afb3f0)"
那么可能的情况是您的代码无法访问 Web 服务,因为它没有提供正确的值
METHOD_NAME="";
NAMESPACE ="";
SOAP_ACTION ="";
URL ="";
我费了很大劲才找到这些基本但重要的价值观来运行ksoap2
METHOD_NAME="";
NAMESPACE ="";
SOAP_ACTION ="";
URL ="";
有各种例子实际上告诉我这个值背后的理论,即如何明智地生成它们
SOAPACTION = 命名空间 + 方法名称。
我继续尝试各种组合,但没有结果。
像我这样对 WebServices 和 Ksoap2 缺乏经验并且大部分时间都在使用 JSON 的人
实际上很沮丧,这些值到底是什么以及如何正确获取它们。
经过以下过程后,您将永远不会遇到找出这些值的困难。
运行您的网络服务
1. 网络服务
它会向您显示一个这样的窗口。
2. WSDL
现在打开它WSDL
通过单击文件中标记的链接来查看其选择WSDL
它看起来像这样。
3.获取WebService的命名空间
现在搜索字符串“Namespace
" using Ctrl+F
你会得到这样的东西
在这里你会注意到我们有two namespaces
targetNamespace="http://tempuri.org/">
<wsdl:import namespace="iscservices.dedicated.co.za"
现在要考虑哪一个,我们稍后将在以下步骤中找到答案
现在该使用哪一个,稍后您就会知道
4. 获取方法名称及其对应的SoapAction
查找您想要访问的方法"PutRecipeImagesPost"
在这种情况下
你会看到有SOAP Action
也在这里为这个方法。
As in Soap action is NameSpace + Methodname
在这里我们可以看到它的使用"iscservices.dedicated.co.za"
所以我们将最终确定为我们的namespace
5. 获取网址
寻找字符串"soap:address location"
该属性的值将是您的 URL
所以最终我们得到了所有需要的值。
根据我们的例子的值
METHOD_NAME="PutRecipeImagesPost";
NAMESPACE ="iscservices.dedicated.co.za";
SOAP_ACTION ="iscservices.dedicated.co.za/InterfaceiPhysioIntelWCFService/PutRecipeImagesPost";
URL ="http://10.0.2.2:51809/iPhysioIntelService.svc/second/";
如果您无法看到上述快照或无法获取这些快照的值WSDl
然后告诉WebService deveoper
解决这个问题。
稍后介绍如何使用KSoap2
请参阅下面的代码片段
SoapObject req = new SoapObject(NAMESPACE,METHOD_NAME);
//SoapObject req = new SoapObject(Namespace_Server,MethodName_Server);
//req.addProperty(KEY, VALUE);
//Key : - parameter name that is there in URL of webservice
//value:- value we want to send to the parameter
req.addProperty("ImageData", data);
req.addProperty("login", CommonStaticData.getusername());
req.addProperty("password",CommonStaticData.getpassword());
req.addProperty("recipeId",FileID);
MarshalBase64 mbase = new MarshalBase64();// marshal is used to serialize the byte array
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelop.bodyOut = req;
envelop.encodingStyle = SoapSerializationEnvelope.ENC2001;
envelop.dotNet = true;
envelop.setOutputSoapObject(req);
HttpTransportSE aht = new HttpTransportSE(URL);
mbase.register(envelop);
aht.call(SOAP_ACTION,envelop);