我必须通过
<?xml version='1.0' enCoding='utf-8' ?><hello><username>test@test.com</username><password>test</password></hello>
至
WSDL
<wsdl:deFinitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/enCoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/Metadata" name="SilentManagerAPI" targetnamespace="http://tempuri.org/"><wsp:Policy wsu:ID="WShttpBinding_ISilentManagerAPI_policy"><wsp:ExactlyOne><wsp:All><wsaw:UsingAddressing/></wsp:All></wsp:ExactlyOne></wsp:Policy><wsdl:types><xsd:schema targetnamespace="http://tempuri.org/imports"><xsd:import schemaLocation="http://myurl.com/Service.svc?xsd=xsd0" namespace="http://tempuri.org/"/><xsd:import schemaLocation="http://myurl.com/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/></xsd:schema></wsdl:types><wsdl:message name="ISilentManagerAPI_Service_inputMessage"><wsdl:part name="parameters" element="tns:Service"/></wsdl:message><wsdl:message name="ISilentManagerAPI_Service_OutputMessage"><wsdl:part name="parameters" element="tns:ServiceResponse"/></wsdl:message><wsdl:portType name="ISilentManagerAPI"><wsdl:operation name="Service"><wsdl:input wsaw:Action="http://tempuri.org/ISilentManagerAPI/Service" message="tns:ISilentManagerAPI_Service_inputMessage"/><wsdl:output wsaw:Action="http://tempuri.org/ISilentManagerAPI/ServiceResponse" message="tns:ISilentManagerAPI_Service_OutputMessage"/></wsdl:operation></wsdl:portType><wsdl:binding name="WShttpBinding_ISilentManagerAPI" type="tns:ISilentManagerAPI"><wsp:PolicyReference URI="#WShttpBinding_ISilentManagerAPI_policy"/><soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="Service"><soap12:operation soapAction="http://tempuri.org/ISilentManagerAPI/Service" /><wsdl:input><soap12:body use="literal"/></wsdl:input><wsdl:output><soap12:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="SilentManagerAPI"><wsdl:port name="WShttpBinding_ISilentManagerAPI" binding="tns:WShttpBinding_ISilentManagerAPI"><soap12:address location="http://myurl.com/Service.svc/Service.svc"/><wsa10:EndpointReference><wsa10:Address>http://myurl.com/Service.svc/Service.svc</wsa10:Address></wsa10:EndpointReference></wsdl:port></wsdl:service></wsdl:deFinitions>
代码尝试:
import androID.os.AsyncTask;import androID.os.Bundle;import androID.util.Log;import androID.Widget.TextVIEw;import androID.app.Activity;import androID.app.Dialog;import androID.app.ProgressDialog;import androID.content.DialogInterface;import androID.content.DialogInterface.OnCancelListener;import java.io.Writer;import org.ksoap2.*;import org.ksoap2.serialization.*;import org.ksoap2.transport.*;import org.xmlpull.v1.XmlSerializer;public class MainActivity extends Activity { private static final String METHOD_name = "Service"; private static final String nameSPACE = "http://tempuri.org/"; private static final String URL = "http://myurl.com/Service.svc"; final String SOAP_ACTION = "http://tempuri.org/ISilentManagerAPI/Service"; TextVIEw tv; StringBuilder sb; private XmlSerializer writer; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextVIEw(this); sb = new StringBuilder(); new testReq().execute(); tv.setText(sb.toString()); setContentVIEw(tv); } class testReq extends AsyncTask<VoID, VoID, VoID> { Dialog dialog; @OverrIDe protected voID onPreExecute() { // Todo auto-generated method stub super.onPreExecute(); dialog = ProgressDialog.show(MainActivity.this, "Please Wait...", "Testing........"); dialog.setCancelable(true); dialog.setonCancelListener(new OnCancelListener() { @OverrIDe public voID onCancel(DialogInterface dialog) { // Todo auto-generated method stub cancel(true); } }); } @OverrIDe protected voID onPostExecute(VoID result) { // Todo auto-generated method stub super.onPostExecute(result); dialog.dismiss(); } @OverrIDe protected VoID doInBackground(VoID... params) { // Todo auto-generated method stub call(); return null; } } public voID call() { try { SoapObject request = new SoapObject(nameSPACE, METHOD_name); PropertyInfo req = new PropertyInfo(); req.name = "hello"; req.type = String.class; req.setValue("<hello>" + "<username>test@test.com</username>" + "<password>test123</password>" + "</hello>"); request.addProperty(req); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setoutputSoapObject(request); httpTransportSE androIDhttpTransport = new httpTransportSE(URL); androIDhttpTransport.call(SOAP_ACTION, envelope); SoapPrimitive result = (SoapPrimitive) envelope.getResponse(); String resultData = result.toString(); Log.i("Result", "" + resultData); sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); e.printstacktrace(); } }}
我在AndroIDManifest.xml中使用互联网权限
<uses-permission androID:name="androID.permission.INTERNET"/>
和输出就像
<hello> <username>any</username> <myoutputdata> . . return data . </myoutputdata></silent>
尝试此代码后获取异常
logcat的
08-01 13:27:53.240: W/System.err(10915): java.io.IOException: http request Failed, http status: 40408-01 13:27:53.300: W/System.err(10915): at org.ksoap2.transport.httpTransportSE.call(httpTransportSE.java:195)08-01 13:27:54.370: W/System.err(10915): at org.ksoap2.transport.httpTransportSE.call(httpTransportSE.java:116)08-01 13:27:54.390: W/System.err(10915): at org.ksoap2.transport.httpTransportSE.call(httpTransportSE.java:111)08-01 13:27:54.410: W/System.err(10915): at com.example.testeset.MainActivity.call(MainActivity.java:105)08-01 13:27:54.440: W/System.err(10915): at com.example.testeset.MainActivity$testReq.doInBackground(MainActivity.java:80)08-01 13:27:54.460: W/System.err(10915): at com.example.testeset.MainActivity$testReq.doInBackground(MainActivity.java:1)08-01 13:27:54.470: W/System.err(10915): at androID.os.AsyncTask.call(AsyncTask.java:264)08-01 13:27:54.480: W/System.err(10915): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)08-01 13:27:54.490: W/System.err(10915): at java.util.concurrent.FutureTask.run(FutureTask.java:137)08-01 13:27:54.500: W/System.err(10915): at androID.os.AsyncTask$SerialExecutor.run(AsyncTask.java:208)08-01 13:27:54.500: W/System.err(10915): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)08-01 13:27:54.500: W/System.err(10915): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)08-01 13:27:54.500: W/System.err(10915): at java.lang.Thread.run(Thread.java:856)
在这里,我得到例外:
androIDhttpTransport.call(SOAP_ACTION, envelope);
解决方法:
如果仍然相关..
首先,您应该将URL更改为http://myurl.com/Service.svc/Service.svc.它将解决404错误.
你应该改变
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
至
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
此外,您应该添加wsa:To和wsa:Action标头,如下所示:
Element e = new Element(); e.setname("To"); e.setnamespace("http://www.w3.org/2005/08/addressing"); e.addChild(Node.TEXT,"http://myurl.com/Service.svc/Service.svc"); Element e1 = new Element(); e1.setname("Action"); e1.setnamespace("http://www.w3.org/2005/08/addressing"); e1.addChild(Node.TEXT,"http://tempuri.org/ISilentManagerAPI/Service"); envelope.headerOut = new Element[]{e,e1};
我希望它有所帮助.
编辑:尝试将req更改为:
PropertyInfo req = new PropertyInfo(); req.name = "xmlstring"; req.namespace=nameSPACE; req.type = String.class; req.setValue("<hello><username>test@test.com</username><password>test</password></hello>"); request.addProperty(req);
即将req.name更改为xmlstring并设置名称空间.
总结以上是内存溢出为你收集整理的获取java.io.IOException:HTTP请求失败,HTTP状态:在ksoap2中404,同时将xml数据传递给soap1.2 android全部内容,希望文章能够帮你解决获取java.io.IOException:HTTP请求失败,HTTP状态:在ksoap2中404,同时将xml数据传递给soap1.2 android所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)