簡體   English   中英

從Android連接到Ms Dynamics導航Web服務

[英]Connecting to Ms dynamics nav web services from android

我正在嘗試使用Ksoap libreries從android應用程序調用ms動態Nav(2013 R2)Web服務,但我不斷收到此異常“ java.lang.IllegalArgumentException:size <= 0”! 不知是什么原因! 你能幫我嗎?!

這是我的代碼:

        import java.io.IOException;
    import java.net.Authenticator;
    import java.net.PasswordAuthentication;
    import java.util.ArrayList;
    import java.util.List;

    import org.ksoap2.HeaderProperty;
    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.PropertyInfo;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;
    import org.xmlpull.v1.XmlPullParserException;

    import android.app.Activity;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;


    public class Main extends Activity {
        private final String namespace = "urn:microsoft-dynamics-schemas/codeunit/MonService";
        private final String url = "http://[@ip]:7047/DynamicsNAV71/WS/ATLAS%20AUTO/Codeunit/MonService";   
        private final String soap_action = "urn:microsoft-dynamics-schemas/codeunit/MonService:Hello";
        private final String method_name = "Hello";
        String great="";
        TextView txt;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

   txt=(TextView)findViewById(R.id.text);
    Button bt=(Button)findViewById(R.id.btn);
    bt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            new Task().execute();


        }
    }) ;


}

public String maMethode(){
    try
    {
          SoapObject request = new SoapObject(namespace, method_name);


          //Property which holds input parameters
            PropertyInfo celsiusPI = new PropertyInfo();
            //Set Name
            celsiusPI.setName("par");
            int n=123;
            //Set Value
            celsiusPI.setValue(n);
            celsiusPI.setType(int.class);
            request.addProperty(celsiusPI);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);


          //envelope.bodyOut=request;
           envelope.dotNet = true;   
           envelope.setOutputSoapObject(request);   
           HttpTransportSE transport = new HttpTransportSE(url);    
           try{

                List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
                headerList.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode("domain\\user:password".getBytes())));
               transport.call(soap_action, envelope);   
           }catch(IOException e )
           {
               e.printStackTrace();
              // System.out.println(e.toString()+"1");
               great=e.toString();
           }
           catch(XmlPullParserException e)
           {
               e.printStackTrace();
               //System.out.println(e.toString()+"2");
               great=e.toString();
           }

           if(envelope.bodyIn != null){
               SoapPrimitive result = (SoapPrimitive) envelope.getResponse(); 

               great= result.toString();
           }
           return great;


    }
    catch (Exception e)
    {
        e.printStackTrace();
       // System.out.println(e.toString()+"" );
        great = e.toString();
        return great;

    }

}



public class Task extends AsyncTask<Void,Void,Void>
{


    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        great=maMethode();
        return null;
    }


    @Override
    protected void onPostExecute(Void result) {
        //Log.i(TAG, "doInBackground");
        txt.setText(great);
    }



}}

這是wsdl:

        <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/MonService" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/MonService">
    <types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/MonService">
    <element name="Hello">
    <complexType>
    <sequence>
    <element minOccurs="1" maxOccurs="1" name="par" type="int"/>
    </sequence>
    </complexType>
    </element>
    <element name="Hello_Result">
    <complexType>
    <sequence>
    <element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
    </sequence>
    </complexType>
    </element>
    </schema>
    </types>
    <message name="Hello">
    <part name="parameters" element="tns:Hello"/>
    </message>
    <message name="Hello_Result">
    <part name="parameters" element="tns:Hello_Result"/>
    </message>
    <portType name="MonService_Port">
    <operation name="Hello">
    <input name="Hello" message="tns:Hello"/>
    <output name="Hello_Result" message="tns:Hello_Result"/>
    </operation>
    </portType>
    <binding name="MonService_Binding" type="tns:MonService_Port">
    <binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="Hello">
    <operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/MonService:Hello" style="document"/>
    <input name="Hello">
    <body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
    </input>
    <output name="Hello_Result">
    <body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
    </output>
    </operation>
    </binding>
    <service name="MonService">
    <port name="MonService_Port" binding="tns:MonService_Binding">
    <address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://@ip:7047/DynamicsNAV71/WS/ATLAS%20AUTO/Codeunit/MonService"/>
    </port>
    </service>
    </definitions>

我建議您使用WCF Storm之類的軟件來測試Web服務端點,並確保您沒有丟失任何參數(例如Hello)。

否則,我們需要更多有關您從NAV暴露的內容的詳細信息,例如Page,Codeunit,Query。 這將為您的WSDL提供一些上下文,而不是Hello重載:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM