我有.net网络服务。我可以使用http访问Android ksoap2库而不会出现问题。使用https时,我得到Http状态:404。我使用www.wsdl2code.com生成我的代码我确信服务部分是正确的,因为我有一个桌面.net客户端,它可以通过https连接。我的证书是签名的,所以我认为它应该“开箱即用”。我正在使用ksoap 3.0.0版本。
下面是logcat:
12-06 12:30:38.733: WARN/System.err(17416): java.io.IOException: HTTP request failed, HTTP status: 404
12-06 12:30:38.743: WARN/System.err(17416): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
12-06 12:30:38.743: WARN/System.err(17416): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
12-06 12:30:38.743: WARN/System.err(17416): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
12-06 12:30:38.743: WARN/System.err(17416): at com.Wsdl2Code.WebServices.WFService.WFService.SendAudio(WFService.java:104)
12-06 12:30:38.743: WARN/System.err(17416): at com.Wsdl2Code.WebServices.WFService.WFService.SendAudio(WFService.java:89)
12-06 12:30:38.743: WARN/System.err(17416): at webServiceCommunication.Service$2.run(WordsFinderService.java:105)
12-06 12:30:38.743: WARN/System.err(17416): at java.lang.Thread.run(Thread.java:841)
这是生成连接的代码的一部分:
public String SendAudio(VectorByte file,List<HeaderProperty> headers){
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.implicitTypes = true;
soapEnvelope.dotNet = true;
SoapObject soapReq = new SoapObject("http://tempuri.org/","SendAudio");
soapReq.addProperty("file",file.toString());
soapEnvelope.setOutputSoapObject(soapReq);
HttpTransportSE httpTransport = new HttpTransportSE(url,timeOut);
try{
if (headers!=null){
httpTransport.call("http://tempuri.org/IWFService/SendAudio", soapEnvelope,headers);
}else{
httpTransport.call("http://tempuri.org/IWFService/SendAudio", soapEnvelope);
}
Object retObj = soapEnvelope.bodyIn;
if (retObj instanceof SoapFault){
SoapFault fault = (SoapFault)retObj;
Exception ex = new Exception(fault.faultstring);
if (eventHandler != null)
eventHandler.Wsdl2CodeFinishedWithException(ex);
}else{
SoapObject result=(SoapObject)retObj;
if (result.getPropertyCount() > 0){
Object obj = result.getProperty(0);
if (obj != null && obj.getClass().equals(SoapPrimitive.class)){
SoapPrimitive j =(SoapPrimitive) obj;
String resultVariable = j.toString();
return resultVariable;
}else if (obj!= null && obj instanceof String){
String resultVariable = (String) obj;
return resultVariable;
}
}
}
}catch (Exception e) {
if (eventHandler != null)
eventHandler.Wsdl2CodeFinishedWithException(e);
e.printStackTrace();
}
return "";
}
我尝试用HttpsTransportSE替换HttpTransportSE,但没有任何改变:
HttpsTransportSE httpTransport = new HttpsTransportSE("example.com",443, "/test/WFService.svc",timeOut);