gpt4 book ai didi

android - 如何在android中传递soap请求

转载 作者:行者123 更新时间:2023-11-29 01:30:41 25 4
gpt4 key购买 nike

这是我的 WSDL 文件 View 。

    <s:element name="ManageUser">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Scenario" type="tns:ManageUserScenario"/>
<s:element minOccurs="0" maxOccurs="1" name="Language" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Userguid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Email" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Firstname" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Lastname" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Address" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="District" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Province" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Country" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Postcode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Phone" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="Newsletter" type="tns:SubscribeNewsletter"/>
</s:sequence>
</s:complexType>
</s:element>
<s:simpleType name="ManageUserScenario">
<s:restriction base="s:string">
<s:enumeration value="Create"/>
<s:enumeration value="Update"/>
</s:restriction>
</s:simpleType>
<s:simpleType name="SubscribeNewsletter">
<s:restriction base="s:string">
<s:enumeration value="X"/>
<s:enumeration value="N"/>
</s:restriction>
</s:simpleType>

我如何为此设置请求。这是我的代码,我没有得到任何回应,但收到警告。请告诉我哪里错了。我的代码:

try {
SoapObject request = new SoapObject(NAMESPACE, METHOD);

request.addProperty("Scenario", "Create");
request.addProperty("Language", "en");
request.addProperty("Username", "abc");
request.addProperty("Email", "abc@gmail.com");
request.addProperty("Password", "abc");
request.addProperty("Firstname", "kumar");
request.addProperty("Lastname", "aryan");
request.addProperty("Userguid", "");
request.addProperty("Phone", "0000000000");
request.addProperty("Address", "");
request.addProperty("District", "");
request.addProperty("Province", "");
request.addProperty("Country", "India");
request.addProperty("Postcode", "");
request.addProperty("Newsletter", "X");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SOAP_VERSION);

envelope.setOutputSoapObject(request);
envelope.dotNet = true;

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
Log.e("Try Block 1", envelope + " - " + request);
androidHttpTransport.call(SOAP_ACTION, envelope);

SoapObject result1 = (SoapObject) envelope.bodyIn;

我也在日志中得到这个:

    W/System.err(32420): org.xmlpull.v1.XmlPullParserException: unexpected type (position:TEXT  To register an ...@2:166 in java.io.InputStreamReader@42885270) 
: at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2045)
: at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:275)
: at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
: at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
: at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
: at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
: at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
: at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
: at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
: at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
: at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
: at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:151)
: at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
: at org.ksoap2.transport.Transport.parseResponse(Transport.java:118)
: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:253)
: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
: at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
: at com.chilindo.SignUpActivity$AsyncTaskRunner.doInBackground(SignUpActivity.java:193)

感谢任何帮助,谢谢。

最佳答案

您好,这是使用 wsdl api 的复杂方法。

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(NAMESPACE + "users.asmx");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.encodingStyle = SoapEnvelope.ENC;

String bodyOut = "<?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/\">";
bodyOut += "<soap:Body><" + METHOD + " xmlns=\""
+ NAMESPACE + "\">";
bodyOut += "<Scenario>" + "Create"
+ "</Scenario><Language>"
+ R.string.language
+ "</Language>"
+ "<Userguid>"
+ ""
+ "</Userguid><Username>"
+ str_username
+ "</Username>"
+ "<Email>"
+ str_email
+ "</Email> <Password>"
+ str_password
+ "</Password><Firstname>"
+ str_first_name
+ "</Firstname>"
+ " <Lastname>"
+ str_last_name
+ "</Lastname><Address>"
+ ""
+ "</Address><District>"
+ ""
+ "</District>"
+ "<Province>"
+ ""
+ "</Province><Country>"
+ str_country
+ "</Country><Postcode>"
+ ""
+ "</Postcode>"
+ "<Phone>"
+ str_phone
+ "</Phone><Newsletter>"
+ news_letter
+ "</Newsletter>";
bodyOut += "</" + METHOD + "></soap:Body></soap:Envelope>";

String xml2 = bodyOut;
// System.out.println("Body " + xml2);
StringEntity se = new StringEntity(xml2, HTTP.UTF_8);
se.setContentType("text/xml");
httpPost.addHeader(SOAP_ACTION, NAMESPACE + "users.asmx");
httpPost.setEntity(se);

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity resEntity = httpResponse.getEntity();
String xml = EntityUtils.toString(resEntity);

关于android - 如何在android中传递soap请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31333944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com