首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xmlpull.v1.XmlPullParserException:预期: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope

Xmlpull.v1.XmlPullParserException:预期: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope
EN

Stack Overflow用户
提问于 2015-07-02 14:36:26
回答 1查看 1.1K关注 0票数 1

我试图在我的应用程序中点击soap api用于登录目的,但得到上面提到的错误,谁能告诉我我哪里出了问题,这是我第一次使用soap api。下面是我使用Soap的代码:

代码语言:javascript
复制
Vector<Object> args = new Vector<Object>();
			Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
			hashtable.put("Email", "mss.siddhart28@gmail.com");
			hashtable.put("Password", "siddharth");
			args.add(hashtable);
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.dotNet = true;
			envelope.xsd = SoapSerializationEnvelope.XSD;
			envelope.enc = SoapSerializationEnvelope.ENC;
			(new MarshalHashtable()).register(envelope);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(
					"http://tempuri.org/", 15000);
			androidHttpTransport.debug = true;
			String result = "";
			try {

				SoapObject request = new SoapObject("http://tempuri.org", "call");
				request.addProperty("resourcePath", "User_Login");
				 request.addProperty("args", args);

				envelope.setOutputSoapObject(request);
				androidHttpTransport.call("call", envelope);
				envelope.setOutputSoapObject(request);
				result = envelope.getResponse().toString();
				Toast.makeText(MainActivity.this, "envelope is" + envelope, Toast.LENGTH_LONG).show();
				System.out.println("result signup: " + result);
			} catch (EOFException e) {
				e.printStackTrace();
				return "restart";
			}

下面是我的wsdl:

代码语言:javascript
复制
POST /w4w/w4wservice.asmx HTTP/1.1
Host: 64.31.2.58
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/User_Login"

<?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:Body>
    <User_Login xmlns="http://tempuri.org/">
      <Email>string</Email>
      <Password>string</Password>
    </User_Login>
  </soap:Body>
</soap:Envelope>

任何帮助都将不胜感激。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-07-02 20:13:29

我终于解决了我的问题..我在这里发布代码,以便其他人可以获得帮助。

代码语言:javascript
复制
private   String SOAP_ACTION = "http://tempuri.org/User_Login";
	private   String METHOD_NAME = "User_Login";
	private   String NAMESPACE = "http://tempuri.org/";
	private   String URL = "http://64.31.2.58:8080/w4w/w4wservice.asmx";

代码语言:javascript
复制
public String logIn() {
			
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.dotNet = true;
			envelope.xsd = SoapSerializationEnvelope.XSD;
			envelope.enc = SoapSerializationEnvelope.ENC;
			(new MarshalHashtable()).register(envelope);
			HttpTransportSE androidHttpTransport = new HttpTransportSE(
					URL, 15000);
			androidHttpTransport.debug = true;
			String result = "";
			try {

				SoapObject request = new SoapObject(NAMESPACE,
						METHOD_NAME);
				request.addProperty("Email", Email);
				request.addProperty("Password", Password);

				envelope.setOutputSoapObject(request);
				androidHttpTransport.call(SOAP_ACTION, envelope);
				result = envelope.getResponse().toString();
				
				System.out.println("result signup: " + result);
			} catch (EOFException e) {
				e.printStackTrace();
				return "restart";
			} catch (SoapFault e) {
				e.printStackTrace();
				if (e.getMessage()
						.contains("Session expired. Try to re-login.")) {
					return "restart";
				}
				return "Email Already Exists";
			} catch (NullPointerException e) {
				e.printStackTrace();
				return "restart";
			} catch (Exception e) {
				e.printStackTrace();
				return "";
			}
			System.out.println("registration result :" + result);
			return result;

		}

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31177154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档