Java 使用SOAP从Android调用Web服务

Java 使用SOAP从Android调用Web服务,java,android,web-services,ksoap2,android-ksoap2,Java,Android,Web Services,Ksoap2,Android Ksoap2,我使用java使用Web服务,我使用下面的WSDL,但我对SOAP\u操作感到困惑: 名称空间: 网址: 方法名称: WSDL 请让我知道问题是什么。我在安卓系统中得到HTTP错误状态500,我想你需要这样做。 您可以从这里看到完整的示例 我希望这将对您有所帮助。确保您使用的名称空间或soap操作正确。当您使用错误的名称空间和soap操作时,就会发生该错误。名称空间和soap操作是否正确? <wsdl:definitions xmlns:soapenc="http://schemas

我使用java使用Web服务,我使用下面的WSDL,但我对SOAP\u操作感到困惑:

名称空间:

网址:

方法名称:

WSDL


请让我知道问题是什么。我在安卓系统中得到HTTP错误状态500,我想你需要这样做。
您可以从这里看到完整的示例


我希望这将对您有所帮助。

确保您使用的名称空间或soap操作正确。当您使用错误的名称空间和soap操作时,就会发生该错误。

名称空间和soap操作是否正确?
<wsdl:definitions 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapjms="http://www.w3.org/2010/soapjms/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://cloudx623.company.com:5555/ws/Monish:TestWebservice/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"name="TestWebservice"
targetNamespace="http://cloudx623.company.com:5555/ws/Monish:TestWebservice/myTest">
<wsdl:types>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:tns="http://localhost:8080/Monish/TestWebservice"
 targetNamespace="http://localhost:8080/Monish/TestWebservice">
   <xsd:element name="myTest" type="tns:myTest"/>
   <xsd:element name="myTestResponse" type="tns:myTestResponse"/>
 <xsd:complexType name="myTest">
   <xsd:sequence>
    <xsd:element name="a" nillable="true" type="xsd:string"/>
    <xsd:element name="b" nillable="true" type="xsd:string"/>
   </xsd:sequence>
   </xsd:complexType>
 <xsd:complexType name="myTestResponse">
 <xsd:sequence>
<xsd:element name="output" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
 <wsdl:message name="TestWebservice_PortType_myTestResponse">
<wsdl:part name="parameters" element="tns:myTestResponse"></wsdl:part>
</wsdl:message>
<wsdl:message name="TestWebservice_PortType_myTest">
<wsdl:part name="parameters" element="tns:myTest"></wsdl:part>
</wsdl:message>
<wsdl:portType name="TestWebservice_PortType">
<wsdl:operation name="myTest">
<wsdl:input message="tns:TestWebservice_PortType_myTest"></wsdl:input>
<wsdl:output message="tns:TestWebservice_PortType_myTestResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Monish_TestWebservice_Binder" type="tns:TestWebservice_PortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="myTest">
<soap:operation soapAction="Monish_TestWebservice_Binder_myTest" style="document"/>
<wsdl:input>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output>
 <soap:body parts="parameters" use="literal"/>
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
<wsdl:service name="TestWebservice">
<wsdl:port name="Monish_TestWebservice_Port" binding="tns:Monish_TestWebservice_Binder">
 <soap:address location="http://192.28.50.46:5555/ws/Monish:TestWebservice/Monish_TestWebservice_Port"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
private static final String SOAP_ACTION = "http://cloudx623.company.com:5555/ws/Monish:TestWebservice/myTest";
private static final String METHOD_NAME = "myTest";
private static final String NAMESPACE = "Monish_TestWebservice_Binder_myTest";
// !!!!! IMPORTANT!!!!! THE URL OF THE CoLDFUSION WEBSERVER NOT LOCALHOST BECAUSE LOCALHOST IS THE ANDROID EMULATOR !!!!!
private static final String URL = "http://192.28.50.46:5555/ws/Monish:TestWebservice?WSDL";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    //CALL the web service method with the two parameters vname and nname
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("a", "3");
            request.addProperty("b", "4");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    envelope.setOutputSoapObject(request);


    HttpTransportSE androidHttpTransport = new HttpTransportSE (URL);                    
    try {
            androidHttpTransport.call(SOAP_ACTION, envelope);

            // Get the SAOP Envelope back and the extract the body
            SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;

            Vector Vec = (Vector) resultsRequestSOAP.getProperty("getMessageReturn");

            //Count of the arrays beneath starting from 0
            //You can see the buildup with the php site with nusoap http://localhost/DA/nusoapclient_test2.php
            int testat = Vec.size();

            // It depends on how many arrays we  have we can get to the attributs of one of them with get(0), get(1) ....
            SoapObject test = (SoapObject) Vec.get(0);
            System.out.println(envelope.getResponse());
            //Get the attributes in the array
            String tem = (String) test.getProperty("a");
            tem = tem + " " + (String) test.getProperty("b");

            //Just show it in a text area field called lblStatus
            ((TextView)findViewById(R.id.lblStatus)).setText(tem.toString());  



            // with androidhttptransport you need a catch block

    } catch(Exception E) {
            ((TextView)findViewById(R.id.lblStatus)).setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());
    }

}