-1

ここにasp.netサービスを作成しましたコードは次のとおりです。

namespace ArttechApps
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string getBoughtApps(String imei)
        {
            return "this is the string to return";// JAVA : SOAP 
        }
    }
}

このサービスを呼び出す Android コードが必要です。これは Java コードです: public static void connect(String url) {

        webServices ws=new webServices("getBoughtApps", "http://tempuri.org/", "http://localhost:12409/getApps.asmx");

        ws.AddProperty("imei", "000000000000000", String.class);

        String res="";
        try 
        {

            SoapObject respuesta = ws.CallWebService();

            res=respuesta.toString();

            Log.d("Response", res);
        } catch (Exception e) 
        {

            e.printStackTrace();
        }
        result=res;
    }

これはアンドロイドのコードです。[編集済み] 誰でも私がそれを行うのを手伝ってくれますか?

4

1 に答える 1

3

ここに、Android 用の KSOAP2 を使用して Web サービスを利用するために使用するクラスがあります。

import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Log;

public class webServices {

    public static String METHOD_NAME;
    public static String NAMESPACE;
    public static String URL;   
    public SoapSerializationEnvelope Envelope_class = null; 
    private SoapObject request;

    public webServices(String NombreMetodo, String Namespace, String URLWService )
    {       
        METHOD_NAME = NombreMetodo;
        NAMESPACE= Namespace;
        URL= URLWService;   
        request= GetSoapObject(METHOD_NAME);
    }

    public void AddProperty(String Name, Object Value ,Type tipo)
    {
        PropertyInfo prop = new PropertyInfo();     
        prop.setName(Name);
        prop.setValue(Value);
        prop.setType(tipo);
        request.addProperty(prop);  
    }

    private SoapObject GetSoapObject (String Methodname)
    {
        return new SoapObject(NAMESPACE,METHOD_NAME);
    }

    private static SoapSerializationEnvelope GetEnvelope(SoapObject Soap)
    {
       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
       envelope.dotNet = true;     
       envelope.setOutputSoapObject(Soap);
       return envelope;

     }

    public SoapObject CallWebService() throws IOException, XmlPullParserException 
    {       
        SoapObject response=null;
        SoapSerializationEnvelope Envelope = GetEnvelope(request);
        Envelope.bodyOut=request;
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);
        androidHttpTransport.debug=true;
        try
           { 

               androidHttpTransport.call(NAMESPACE + METHOD_NAME, Envelope);              
               response = (SoapObject) Envelope.getResponse();      
               Envelope_class = Envelope;
           }
        catch(Exception e)
        {
            e.printStackTrace();
            Log.d("AndroidRequest",androidHttpTransport.requestDump);
            Log.d("AndroidResponse",androidHttpTransport.responseDump);
            return null;
        }   

        return response;
    }

    public Object CallWebServicePrimitive() throws SoapFault
    {
        SoapObject request = GetSoapObject(METHOD_NAME);    
        SoapSerializationEnvelope Envelope = GetEnvelope(request);

         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
         try {
            androidHttpTransport.call(NAMESPACE + METHOD_NAME, Envelope);
        } catch (IOException e) {
            Log.d("ErrorApp", e.getMessage().toString());
        } catch (XmlPullParserException e) {
            Log.d("ErrorApp", e.getMessage().toString());
        }   

        SoapPrimitive response= (SoapPrimitive) Envelope.getResponse();
        return response;
    }

}

WCF サービスを使用している場合は、次を変更する必要があります。

SoapSerializationEnvelope(SoapEnvelope.VER11) から: SoapSerializationEnvelope(SoapEnvelope.VER12)

URLをSVC URLに向けます

于 2012-11-16T11:54:58.630 に答える