0

我正在使用 java 使用 web 服务,我正在使用下面的 WSDL,但我对 SOAP_ACTION 感到困惑:

命名空间:

网址:

方法名:

WSDL

<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>

使用 ksoap2 的 Java 代码如下

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());
    }

}

请让我知道问题是什么。我在 Android 中收到 HTTP 错误状态 500

4

2 回答 2

2

我认为你需要达到这样的目标。
您可以从此处查看完整示例。

第 1 部分:从 Android 调用 Web 服务

第 2 部分:使用数据库在 Android 中运行的 Web 服务

我希望这能帮到您。

于 2013-10-17T07:24:45.343 回答
0

确保您使用正确的命名空间或肥皂动作。当您使用错误的一个时,就会发生该错误。

于 2013-10-21T06:21:43.803 回答