简体   繁体   English

从Android连接到Ms Dynamics导航Web服务

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

I'm trying to call a ms dynamics Nav (2013 R2) web service from an android application using Ksoap libreries, but i keep getting this exception "java.lang.IllegalArgumentException:size<=0" ! 我正在尝试使用Ksoap libreries从android应用程序调用ms动态Nav(2013 R2)Web服务,但我不断收到此异常“ java.lang.IllegalArgumentException:size <= 0”! I do not know what can be the reason! 不知是什么原因! Can you help me please?! 你能帮我吗?!

this is my code: 这是我的代码:

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



}}

this is the wsdl: 这是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>

I'd suggest using a piece of software like WCF Storm to test the Web Service endpoint and ensure you're not missing any parameters (Eg Hello). 我建议您使用WCF Storm之类的软件来测试Web服务端点,并确保您没有丢失任何参数(例如Hello)。

Otherwise we need some more detail about what you're exposing from NAV, eg Page, Codeunit, Query. 否则,我们需要更多有关您从NAV暴露的内容的详细信息,例如Page,Codeunit,Query。 This will give your WSDL some context rather than a Hello overload :) 这将为您的WSDL提供一些上下文,而不是Hello重载:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM