php - Android 客户端 : Web service - what's the correct SOAP_ACTION, METHOD_NAME、NAMESPACE、我应该使用的 URL?

标签 php android web-services soap

如果我想使用以下 Web 服务(help.be 只是一个示例,假设它确实存在):http://www.help.be/webservice/webservice_help.php (它是用 PHP=client's choice,而不是 .NET 编写的)具有以下 WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" name="webservice_help" targetNamespace="http://www.help.be/webservice/webservice_help.php" xmlns:tns="http://www.help.be/webservice/webservice_help.php" xmlns:impl="http://www.help.be/webservice/webservice_help.php" xmlns:xsd1="http://www.help.be/webservice/webservice_help.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
  <portType name="webservice_helpPortType">
    <operation name="webservice_help">
        <input message="tns:Webservice_helpRequest"/>
    </operation>
    <operation name="getLocation" parameterOrder="input">
        <input message="tns:GetLocationRequest"/>
        <output message="tns:GetLocationResponse"/>
    </operation>


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" name="webservice_help" targetNamespace="http://www.help.be/webservice/webservice_help.php" xmlns:tns="http://www.help.be/webservice/webservice_help.php" xmlns:impl="http://www.help.be/webservice/webservice_help.php" xmlns:xsd1="http://www.help.be/webservice/webservice_help.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    <portType name="webservice_helpPortType">
        <operation name="webservice_help">
            <input message="tns:Webservice_helpRequest"/>
        </operation>
        <operation name="getLocation" parameterOrder="input">
            <input message="tns:GetLocationRequest"/>
            <output message="tns:GetLocationResponse"/>
        </operation>

        <operation name="getStationDetail" parameterOrder="input">
            <input message="tns:GetStationDetailRequest"/>
            <output message="tns:GetStationDetailResponse"/>
        </operation>
        <operation name="getStationList" parameterOrder="input">
            <input message="tns:GetStationListRequest"/>
            <output message="tns:GetStationListResponse"/>
        </operation>
    </portType>

    <binding name="webservice_helpBinding" type="tns:webservice_helpPortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="webservice_help">
            <soap:operation soapAction="urn:webservice_help#webservice_helpServer#webservice_help"/>
            <input>
                <soap:body use="encoded" namespace="http://www.help.be/webservice/webservice_help.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
        </operation>
        <operation name="getLocation">
            <soap:operation soapAction="urn:webservice_help#webservice_helpServer#getLocation"/>
            <input>
                <soap:body parts="input" use="encoded" namespace="http://www.help.be/webservice/webservice_help.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output>
                <soap:body parts="return" use="encoded" namespace="http://www.help.be/webservice/webservice_help.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
        <operation name="getStationDetail">
            <soap:operation soapAction="urn:webservice_help#webservice_helpServer#getStationDetail"/>
            <input>
                <soap:body parts="input" use="encoded" namespace="http://www.help.be/webservice/webservice_help.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output>
                <soap:body parts="return" use="encoded" namespace="http://www.help.be/webservice/webservice_help.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
        <operation name="getStationList">
            <soap:operation soapAction="urn:webservice_help#webservice_helpServer#getStationList"/>
            <input>
                <soap:body parts="input" use="encoded" namespace="http://www.help.be/webservice/webservice_help.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output>
                <soap:body parts="return" use="encoded" namespace="http://www.help.be/webservice/webservice_help.php" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
    </binding>

    <message name="Webservice_helpRequest"/>
    <message name="GetLocationRequest">
        <part name="input" type="xsd:array"/>
    </message>
    <message name="GetLocationResponse">
        <part name="return" type="xsd:array"/>
    </message>
    <message name="GetStationDetailRequest">
        <part name="input" type="xsd:array"/>

    </message>
    <message name="GetStationDetailResponse">
        <part name="return" type="xsd:string"/>
    </message>
    <message name="GetStationListRequest">
        <part name="input" type="xsd:array"/>
    </message>
    <message name="GetStationListResponse">
        <part name="return" type="xsd:string"/>

    </message>
    <service name="webservice_helpService">
        <port name="webservice_helpPort" binding="tns:webservice_helpBinding">
            <soap:address location="http://www.help.be/webservice/webservice_help.php"/>
        </port>
    </service>
</definitions>

我应该在下面使用的正确 SOAP_ACTION、METHOD_NAME、NAMESPACE、URL 是什么?

我试过这个:

public class Main extends Activity {
    /** Called when the activity is first created. */

    private static final String SOAP_ACTION_GETLOCATION = "getLocation";
    private static final String METHOD_NAME_GETLOCATION = "getLocation";            
    private static final String NAMESPACE = "http://www.help.be/webservice/";
    private static final String URL = "http://www.help.be/webservice/webservice_help.php";

    TextView tv;

    @SuppressWarnings("unchecked")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv = (TextView)findViewById(R.id.TextView01);

        // --------------------------------------------------------------------------------------
        SoapObject request_location = new SoapObject(NAMESPACE, METHOD_NAME_GETLOCATION);       
        request_location.addProperty("login", "login");         // -> string required 
        request_location.addProperty("password", "password");   // -> string required
        request_location.addProperty("serial", "serial");       // -> string required
        request_location.addProperty("language", "fr");         // -> string required (available « fr,nl,uk,de ») 
        request_location.addProperty("keyword", "Braine");      // -> string required

        // --------------------------------------------------------------------------------------

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        //soapEnvelope.dotNet = true;                           // don't forget it for .NET WebServices !
        soapEnvelope.setOutputSoapObject(request_location);


        AndroidHttpTransport aht = new AndroidHttpTransport(URL);

        try { 
            aht.call(SOAP_ACTION_GETLOCATION, soapEnvelope); 

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

            Vector XXXX = (Vector) resultsRequestSOAP.getProperty("GetLocationResponse"); 

            int vector_size = XXXX.size(); 
            Log.i("Hub", "testat="+vector_size);

            tv.setText("OK");  

        } catch(Exception E) { 
            tv.setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());
            Log.i("Hub", "Exception E");
            Log.i("Hub", "E.getClass().getName()="+E.getClass().getName()); 
            Log.i("Hub", "E.getMessage()="+E.getMessage()); 
        } 
        // --------------------------------------------------------------------------------------
    }
}

我不确定必须使用的 SOAP_ACTION、METHOD_NAME、NAMESPACE 和 URL?因为 soapAction 指向 URN 而不是传统的 URL,而且它是 PHP 而不是 .NET ...

另外,我不确定是否必须使用 request_location.addProperty("login", "login");
request_location.addAttribute("login", "login"); 的?

=>

<message name="GetLocationRequest">
<part name="input" type="xsd:array"/>

你会怎么说?

感谢您的帮助。

H.

编辑:这是一些在 PHP 中工作的代码——我只是想在 Android/JAVA 中使用相同的代码:

<?php
    ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache 

    $request['login'] = 'login';
    $request['password'] = 'password';
    $request['serial'] = 'serial';
    $request['language'] = 'fr';

      $client= new SoapClient("http://www.test.be/webservice/webservice_test.wsdl");    

    print_r( $client->__getFunctions());

    ?><hr><h1>getLocation</h1>
    <h2>Input:</h2>
    <?
    $request['keyword'] = 'Bruxelles';
    print_r($request);
    ?><h2>Result</h2><?
     $result = $client->getLocation($request);
     print_r($result);   
?>

最佳答案

String SOAP_ACTION = "http://tempuri.org/Add"; 
        String METHOD_NAME = "Add"; 
        String NAMESPACE = "http://tempuri.org/"; 
        String URL = "http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx"; 

可以在以下位置找到上述示例的 wsdl:http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?WSDL

在你的情况下, METHOD_NAME = "getStationDetail"或 METHOD_NAME = "getStationList"或 METHOD_NAME = "getLocation"

关于php - Android 客户端 : Web service - what's the correct SOAP_ACTION, METHOD_NAME、NAMESPACE、我应该使用的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2744617/

相关文章:

rest - WCF RESTFul 服务中的异常处理

php - 结果不与存储过程调用MySQL php绑定(bind)

java - 多个 if 语句

java - 使用静态内部类创建java单例

SharePoint 2010 Web 服务上的 Java JBoss 401 错误

java - 与 salesforce 的双向同步 (java)

php - 带有2个参数的函数内的mysql查询

php - 插入但如果重复则忽略,如果存在于另一个表中则设置不同的值

php - mysql_connect() : Access denied for user 'root'

java - 禁用后退,最近的应用程序按钮,电源按钮,主页和主页长按按钮