使用KSOAP库进行调用时WSDL调用获取错误

时间:2019-01-11 03:08:33

标签: android wsdl ksoap

在所有使用REST Webservice的项目之前,我在SOAP / WSDL调用Webservice中是一个新手。经过大量的教程和示例之后,我尝试在我的Android项目中调用SOAP / WSDL文件webservice,但是当我调用logCat show error时,如下所示:

LogCat错误:

    2019-01-11 10:37:22.304 28676-28799/com.example.alhaadia.obsintructor 
    D/test: URL = http://13.76.153.12/OBS/MessageBroker.svc?wsdl
    2019-01-11 10:37:22.304 28676-28799/com.example.alhaadia.obsintructor 
    D/test: request= HelloWorld{}
    2019-01-11 10:37:22.308 28676-28799/com.example.alhaadia.obsintructor 
    D/NetworkSecurityConfig: No Network Security Config specified, using 
    platform default
    2019-01-11 10:37:22.330 28676-28799/com.example.alhaadia.obsintructor 
    D/test: Error - org.ksoap2.transport.HttpResponseException: HTTP request 
    failed, HTTP status: 404
    2019-01-11 10:37:22.331 28676-28799/com.example.alhaadia.obsintructor 
   W/System.err: org.ksoap2.transport.HttpResponseException: HTTP request 
   failed, HTTP status: 404
    2019-01-11 10:37:22.331 28676-28799/com.example.alhaadia.obsintructor 
   W/System.err:     at 
   org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:235)
    2019-01-11 10:37:22.331 28676-28799/com.example.alhaadia.obsintructor 
    W/System.err:     at 
   org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
    2019-01-11 10:37:22.331 28676-28799/com.example.alhaadia.obsintructor 
   W/System.err:     at 
   org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
    2019-01-11 10:37:22.331 28676-28799/com.example.alhaadia.obsintructor 
   W/System.err:     at 
   com.example.alhaadia.obsintructor.MainActivity$4.run(MainActivity.java:311)

我知道错误404的意思是,也许我使用的链接是错误的,但是这里还有其他地方我做错了什么。是我的NAMESPACE,ACTIONNAME,URL,METHODNAME是正确的吗?

这是我的WSDL文件,

    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
   xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" 
   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss- 
   wssecurity-utility-1.0.xsd" 
   xmlns:wsa10="http://www.w3.org/2005/08/addressing" 
   xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
   xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
   xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
   xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
   xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
   xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/" 
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
   xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
   xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
   name="MessageBroker" targetNamespace="http://tempuri.org/">
        <link type="text/css" id="dark-mode" rel="stylesheet" href=""/>
        <style type="text/css" id="dark-mode-custom-style"/>
        <wsdl:types>
        <xsd:schema targetNamespace="http://tempuri.org/Imports">
        <xsd:import schemaLocation="http://13.76.153.12/OBS/MessageBroker.svc? 
   xsd=xsd0" namespace="http://tempuri.org/"/>
        <xsd:import schemaLocation="http://13.76.153.12/OBS/MessageBroker.svc? 
   xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
        <xsd:import schemaLocation="http://13.76.153.12/OBS/MessageBroker.svc? 
   xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/MapLocation"/>
        </xsd:schema>
        </wsdl:types>
        <wsdl:message name="IMessageBroker_HelloWorld_InputMessage">
        <wsdl:part name="parameters" element="tns:HelloWorld"/>
        </wsdl:message>
        <wsdl:message name="IMessageBroker_HelloWorld_OutputMessage">
        <wsdl:part name="parameters" element="tns:HelloWorldResponse"/>
        </wsdl:message>
   <wsdl:portType name="IMessageBroker">
   <wsdl:operation name="HelloWorld">
   <wsdl:input wsaw:Action="http://tempuri.org/IMessageBroker/HelloWorld" 
   message="tns:IMessageBroker_HelloWorld_InputMessage"/>
   <wsdl:output 
   wsaw:Action="http://tempuri.org/IMessageBroker/HelloWorldResponse" 
   message="tns:IMessageBroker_HelloWorld_OutputMessage"/>
   </wsdl:operation>
   </wsdl:portType>
   </wsdl:definitions>

所以在我的Android项目中,我这样称呼:

String SOAP_ACTION = "http://tempuri.org/IMessageBroker/HelloWorld";
String METHOD_NAME = "HelloWorld";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://13.76.153.12/OBS/MessageBroker.svc?wsdl";

 try {
       SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
       SoapSerializationEnvelope soapSerializationEnvelope 
       = new SoapSerializationEnvelope(SoapEnvelope.VER12);
       soapSerializationEnvelope.dotNet = true;
                        Log.d("test", "URL = " + URL);
                        Log.d("test", "request= " + request.toString());

     soapSerializationEnvelope.setOutputSoapObject(request);
     HttpTransportSE transportSE = newHttpTransportSE(URL);
     transportSE.debug = true;
     transportSE.call(SOAP_ACTION, 
     soapSerializationEnvelope);

    String result = soapSerializationEnvelope.getResponse().toString();
     MyProperties.showLogD("wsdl", "login: " + result);
     Log.i("Success", "calculate: " + result);
      } catch (Throwable e) {
       Log.d("test", "Error - " + e.toString());
       e.printStackTrace();
       }

我的PM表示此API仍在开发中,但是第三部分表示他可以在以下链接中访问此HelloWorld方法:http://13.76.153.12/OBS/MessageBroker.svc/HelloWorld。那是什么让我感到困惑,为什么他可以使用该链接访问HelloWorld方法,如何获得该链接,WSDL文件中是否存在? 。当我尝试使用SOAPUi时,请求方法什么也不显示。

现在我想知道为什么会这样,这是因为WSDL正在开发中,但是为什么测试人员(第三方)可以看到Hello World的结果,他是如何做到的。然后请检查我的NAMESPACE,ACTIONNAME,URL,METHODNAME是否正确?提前致谢。

注意:现在没有人可以帮助我,我是这里唯一的Android开发人员。

0 个答案:

没有答案