android 用soap库访问wsdl的问题
巴扎黑
巴扎黑 2017-04-17 13:26:30
0
2
611
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost:88/Service.php"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
    name="userOperService" targetNamespace="http://localhost:88/Service.php">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://localhost:88/Service.php" targetNamespace="http://localhost:88/Service.php"
            version="1.0">
            <xs:element name="operReq_En" type="tns:userOperServiceRequest" />
            <xs:element name="operReqResponse_En" type="tns:userOperServiceResponse" />
            <xs:complexType name="userOperServiceRequest">
                <xs:sequence>
                    <xs:element name="operateType" type="xs:string" />
                    <xs:element minOccurs="0" name="operRequestParam" type="xs:string" />
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="userOperServiceResponse">
                <xs:sequence>                   
                    <xs:element minOccurs="0" name="responseSysCode" type="xs:string" />
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="operReqResponse_En">
        <wsdl:part element="tns:operReqResponse_En" name="parameters"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="operReq_En">
        <wsdl:part element="tns:operReq_En" name="parameters"></wsdl:part>
    </wsdl:message>
    <wsdl:portType name="userOperInterfaces">
        <wsdl:operation name="operReq_En">
            <wsdl:input message="tns:operReq_En" name="operReq_En"></wsdl:input>
            <wsdl:output message="tns:operReqResponse_En" name="operReqResponse_En"></wsdl:output>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="userOperServiceSoapBinding" type="tns:userOperInterfaces">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="operReq_En">
            <soap:operation soapAction="operReq_En" style="document" />
            <wsdl:input name="operReq_En">
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="operReqResponse_En">
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="userOperService">
        <wsdl:port binding="tns:userOperServiceSoapBinding" name="userOperServer">
            <soap:address
                location="http://localhost:88/Service.php" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

上面是wsdl文件,安卓调用时需要传递下面几个参数:METHOD_NAME、NAMESPACE、SOAP_ACTION、URL。我试了很多次都报不一样的错误,求大神解答,上面的四个参数分别对应什么?

真不是我懒Zzzzz网上搜的不靠谱,我都搞了两三天了,望做过这方面的大神赐教啊

package com.example.xx;

import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;


@TargetApi(Build.VERSION_CODES.GINGERBREAD) public class MainActivity extends Activity {

    private static final String METHOD_NAME = "operReq_En";
    private static final String NAMESPACE = "http://192.168.1.119:88/User/Service.php";  //guding
    private TextSwitcher textswitch;
    String url = "http://192.168.1.119:88/User/Service.php";   //guding
    SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
    private static final String SOAP_ACTION = "http://192.168.1.119:88/User/Service/operReq_En";

    @TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint("NewApi") @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        this.textswitch=(TextSwitcher) findViewById(R.id.textSwitcher1);
        this.textswitch.setFactory(new ViewFactoryImp());

        rpc.addProperty("operateType", "AUTH");
        rpc.addProperty("operRequestParam", "13977618061,780121");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
        envelope.bodyOut = rpc;
        HttpTransportSE transport = new HttpTransportSE(url);
        try {
            transport.call(SOAP_ACTION, envelope);
 //           Object object =(Object)envelope.getResponse();
//            Object result = (Object)envelope.getResponse();
            SoapObject object = (SoapObject) envelope.bodyIn;
            String result = object.getProperty(0).toString();
            MainActivity.this.textswitch.setText(result.toString());
        } catch (Exception e) {
            e.printStackTrace();
            MainActivity.this.textswitch.setText(e.toString());
        }
    }

    private class ViewFactoryImp implements ViewFactory{
        public View makeView() {
        TextView txt=new TextView(MainActivity.this);
        txt.setTextSize(30);
        return txt;
        }
        }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

经过进一步的修改,上面是我的安卓程序,但是报错java.lang.ClassCastException:org.ksoap2.SoapFault cannot be cast to org.ksoap2.serizlization.SopaObject

然后,接收数据我又做以下更改,Object result = (Object)envelope.getResponse();
报错信息:SoapFault -faultcode:'SOAP-ENV:Server' faultstring:'Procedure' operReq_En 'not present' faultactor:'null' detail:null.
为什么没有返回值?

巴扎黑
巴扎黑

Antworte allen(2)
刘奇
<wsdl:binding name="userOperServiceSoapBinding" type="tns:userOperInterfaces">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="operReq_En"> // 方法名称
            <soap:operation soapAction="operReq_En" style="document" /> // soap_action是你要绑定的该方法的地址
            <wsdl:input name="operReq_En">
                <soap:body use="literal" /> // 输入
            </wsdl:input>
            <wsdl:output name="operReqResponse_En">
                <soap:body use="literal" /> // 返回值
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

简单的讲
METHOD_NAME <wsdl:operation name="operReq_En">
SOAP_ACTION <soap:operation soapAction="http://localhost:88/Service/operReq_En" style="document" />
URL <soap:address location="http://localhost:88/Service/" />

你的调用SOAP消息和错误提示呢?

小葫芦

大哥 你这个做成功了吗,我现在需要跟你做一个一样的事情,能不能教下我 QQ691511237拜托拜托

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!