Android ksoap2名称空间,url,soap_action,使用wcf的方法值

时间:2014-10-14 00:44:22

标签: android wcf wsdl

我正在使用wcf服务器进行应用程序。但是关于ksoap2方法,url,soap_action,方法存在一些问题。

-<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:tns="http://tempuri.org/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/" name="ProductService">


-<wsdl:types>


-<xsd:schema targetNamespace="http://tempuri.org/Imports">

<xsd:import namespace="http://tempuri.org/" schemaLocation="http://localhost:8000/ProductService?xsd=xsd0"/>

<xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="http://localhost:8000/ProductService?xsd=xsd1"/>

</xsd:schema>

</wsdl:types>


-<wsdl:message name="IProductService_GetFirstName_InputMessage">

<wsdl:part name="parameters" element="tns:GetFirstName"/>

</wsdl:message>


-<wsdl:message name="IProductService_GetFirstName_OutputMessage">

<wsdl:part name="parameters" element="tns:GetFirstNameResponse"/>

</wsdl:message>


-<wsdl:portType name="IProductService">


-<wsdl:operation name="GetFirstName">

<wsdl:input message="tns:IProductService_GetFirstName_InputMessage" wsaw:Action="http://tempuri.org/IProductService/GetFirstName"/>

<wsdl:output message="tns:IProductService_GetFirstName_OutputMessage" wsaw:Action="http://tempuri.org/IProductService/GetFirstNameResponse"/>

</wsdl:operation>

</wsdl:portType>


-<wsdl:binding name="BasicHttpBinding_IProductService" type="tns:IProductService">

<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>


-<wsdl:operation name="GetFirstName">

<soap:operation style="document" soapAction="http://tempuri.org/IProductService/GetFirstName"/>


-<wsdl:input>

<soap:body use="literal"/>

</wsdl:input>


-<wsdl:output>

<soap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>


-<wsdl:service name="ProductService">


-<wsdl:port name="BasicHttpBinding_IProductService" binding="tns:BasicHttpBinding_IProductService">

<soap:address location="http://localhost:8000/ProductService"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

这是我的wsdl网页。

我认为我的ksoap2变量是

private final String NAMESPACE = "http:/tempuri.org/";  
private final String URL = "http://10.118.52.133:8000/ProductService.asmx";
private final String SOAP_ACTION = "http://tempuri.org/GetFirstName";  
private final String METHOD_NAME = "GetFirstName";  

也许这是错误的,因为我的应用程序没有结果。

虽然我已经回答了类似的问题,但我无法找到答案。

所以有人帮助我。

感谢。

添加我的完整代码

package com.axis.soapaccess;   

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE;   
import android.os.Bundle; 
import android.os.Handler; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.TextView;   

public class MainActivity extends Activity 
{     
    //change following variables according to the WSDL  
    private final String NAMESPACE = "http://tempuri.org/";  
    private final String URL = "http://10.118.52.133:8000/ProductService?wsdl";
    private final String SOAP_ACTION = "http://tempuri.org/GetFirstName";  
    private final String METHOD_NAME = "GetFirstName";    
    private String Webresponse = "";  
    private TextView textView;  
    private Thread thread;  
    private Handler handler = new Handler();    

@Override protected void onCreate(Bundle savedInstanceState) 
{   
    super.onCreate(savedInstanceState);   
    setContentView(R.layout.activity_main);   
    textView = (TextView) findViewById(R.id.textView1);   
    webAccess();  
}        

public void webAccess()
{   
    thread = new Thread(){    
        public void run(){     
            try{       
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);           
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
                envelope.dotNet = true;          
                envelope.setOutputSoapObject(request);          
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);        
                androidHttpTransport.call(SOAP_ACTION, envelope);      ***// Error was caused by this line. Null exception***          
                SoapPrimitive response = (SoapPrimitive)envelope.getResponse();             
                Webresponse = response.toString();     
                }           
            catch(Exception e){      
                e.printStackTrace();     
                }           

            handler.post(createUI);    
            }   
        };       

        thread.start();  
}        

final Runnable createUI = new Runnable() {   
    public void run(){   
        textView.setText(Webresponse);  
        }  
    };     

    @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;  
    }   

}

现在还在工作。 当我调试这一行时(androidHttpTransport.call(SOAP_ACTION,envelope);

connection=null
debug=false
proxy=null
requestDump=null
responesDump=null
timeout=20000
url="http://10.118.52.133:8000/ProductService.asmx" (id=830046061280)
xmlVersionTag=""(id=830028910544)

org.ksoap2.transport.HttpTransportSE@429eaf68

1 个答案:

答案 0 :(得分:0)

请尝试以下链接

http://android.vexedlogic.com/2011/04/30/android-lists-v-accessing-and-consuming-a-soap-web-service-ii/

private class SoapAccessTask1 extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... urls) {

        String webResponse = "";
        try {
            final String NAMESPACE = "http://tempuri.org/";
            final String URL = "http://www.10.118.52.133.com/ProductService.asmx";
            final String SOAP_ACTION = "http://tempuri.org/GetFirstName";
            final String METHOD_NAME = "GetFirstName";

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo info = new PropertyInfo();
            info.setName("StationID");
            info.setValue(1);
            info.setType(Integer.class);
            request.addProperty(info);

            PropertyInfo info11 = new PropertyInfo();
            info11.setName("Rows");
            info11.setValue(1);
            info11.setType(Integer.class);
            request.addProperty(info11);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.debug = true;
            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);

                MyDeptt = androidHttpTransport.responseDump;
                Log.e("test", "MyDept:--" + MyDeptt);
                webResponse = MyDeptt;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {

            Toast.makeText(context,
                    "Cannot access the web service" + e.toString(),
                    Toast.LENGTH_LONG).show();

        }
        return webResponse;

    }
}