Android Development note "calling. NET WebService problems"

Source: Internet
Author: User
Tags dotnet soap

1, an exception occurred:org.ksoap2.SoapFault

Soapfault-faultcode: ' Soap:server ' faultstring: ' The server cannot process the request. ---> Failed to load a file or assembly "Mysql.data, version=6.3.9.0, culture=neutral, publickeytoken=c5687fc88969c44d" or one of its dependencies. The system cannot find the file specified. ' Faultactor: ' null ' detail: [email protected]

Cause: A strongly typed DataSet (DataSet) is used in WebService to connect to MySQL database, simplifying database bottom-up development

Solution: Install Mysql-connector-net-6.3.9.msi on it, the article has an address

2, Android access WebService help class, the source code is as follows:

 PackageCom.sinobpo.nbsmt.webservice;Importjava.io.IOException;Importjava.io.UnsupportedEncodingException;Importjava.util.ArrayList;ImportJava.util.Iterator;Importjava.util.List;ImportJava.util.Map;ImportJava.util.Set;ImportOrg.apache.http.NameValuePair;Importorg.apache.http.client.ClientProtocolException;Importorg.apache.http.client.HttpClient;ImportOrg.apache.http.client.ResponseHandler;Importorg.apache.http.client.entity.UrlEncodedFormEntity;ImportOrg.apache.http.client.methods.HttpPost;ImportOrg.apache.http.impl.client.BasicResponseHandler;Importorg.apache.http.impl.client.DefaultHttpClient;ImportOrg.apache.http.message.BasicNameValuePair;ImportOrg.apache.http.params.BasicHttpParams;ImportOrg.apache.http.params.HttpConnectionParams;ImportOrg.apache.http.params.HttpParams;ImportOrg.ksoap2.SoapEnvelope;ImportOrg.ksoap2.serialization.SoapObject;Importorg.ksoap2.serialization.SoapPrimitive;ImportOrg.ksoap2.serialization.SoapSerializationEnvelope;ImportOrg.ksoap2.transport.HttpTransportSE; Public classWebserviceutil {/***. Net WebService Calling Method * *@paramNameSpace *@paramMethodName *@paramWebServiceURL *@paramMap *@return     */     Public Staticstring Docallwebservice (String nameSpace, String methodName, string webserviceurl, map map) {Strin G Xmlstr=NULL; Soapobject _soapobject=NewSoapobject (NameSpace, methodName); //If there are parameters, set the call method parameterSet _keyset = Map.keyset ();//returns a collection of keysIterator _iterator =_keyset.iterator ();  while(_iterator.hasnext ())//The first iteration takes the key value{Object key=_iterator.next ();        _soapobject.addproperty (Key.tostring (), Map.get (key)); }        Try{soapserializationenvelope Envelope=NewSoapserializationenvelope (SOAPENVELOPE.VER11); //whether the. NETWebService can be called.Envelope.dotnet =true;            Envelope.setoutputsoapobject (_soapobject); Httptransportse HT=NewHttptransportse (WebServiceURL, 5000); Ht.call (NameSpace+methodName, envelope); if(Envelope.getresponse ()! =NULL) {soapprimitive response=(soapprimitive) envelope.getresponse (); Xmlstr=response.tostring (); }        } Catch(Exception e) {System.out.println ("Prop:" +e.tostring ());            E.printstacktrace (); return NULL; }        returnXmlstr; }    /*** Java WebService Calling method * *@paramNameSpace *@paramMethodName *@paramWebServiceURL *@paramMap *@return     */     Public Staticstring Docallwebserviceforjava (String nameSpace, String methodName, string webserviceurl, map map) { String Xmlstr=NULL; //To Create a Httptransportse transport objectHttptransportse HT =NewHttptransportse (WebServiceURL); Ht.debug=true; //creating envelop objects using the soap1.1 protocolSoapserializationenvelope envelope =NewSoapserializationenvelope (SOAPENVELOPE.VER11); //instantiating a Soapobject objectSoapobject request =NewSoapobject (NameSpace, methodName); /*** Set parameters, parameter names do not need to be the same as the server side of the call parameter name, only need the corresponding order of the same **/        //If there are parameters, set the call method parameterSet _keyset = Map.keyset ();//returns a collection of keysIterator _iterator =_keyset.iterator ();  while(_iterator.hasnext ())//The first iteration takes the key value{Object key=_iterator.next ();        Request.addproperty (Key.tostring (), Map.get (key)); }        //Request.addproperty ("JSON", "YYYY"); //SoapHeader is here .//element[] Header = new element[1]; //element LV = new Element (). createelement (NameSpace, "json"); //Lv.addchild (Node.text, ""); //set the Soapobject object to an outgoing SOAP message for the Soapserializationenvelope objectEnvelope.bodyout =request; //envelope.dotnet = false;        Try {            //Call WebServiceHt.call (NULL, envelope); if(Envelope.getresponse ()! =NULL) {                //soapobject result = (soapobject) Envelope.bodyin; //String name = Envelope.bodyIn.toString ();System.out.println ("envelope.getresponse () =" +envelope.getresponse (). toString ()); Xmlstr= ""; } Else{xmlstr=NULL; }        } Catch(Exception e) {System.out.println ("Prop:" +e.tostring ());        E.printstacktrace (); }        returnXmlstr; }     Public Staticstring docallwebserviceforphp (String webserviceurl) {string Xmlstr=NULL; Httpparams Httpparams=NewBasichttpparams (); Httpconnectionparams.setconnectiontimeout (Httpparams,5000); Httpconnectionparams.setsotimeout (Httpparams,5000); Httpparams P=NewBasichttpparams (); P.setparameter ("User", "1"); HttpClient HttpClient=Newdefaulthttpclient (P); HttpPost HttpPost=NewHttpPost (WebServiceURL); List<NameValuePair> Namevaluepairs =NewArraylist<namevaluepair> (2); Namevaluepairs.add (NewBasicnamevaluepair ("User", "1")); Try{httppost.setentity (Newurlencodedformentity (namevaluepairs)); ResponseHandler<String> ResponseHandler =NewBasicresponsehandler (); Xmlstr=Httpclient.execute (HttpPost, ResponseHandler); } Catch(unsupportedencodingexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(clientprotocolexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }                returnXmlstr; }}

3. Invalid project description

A, this error is simply translated as: Invalid item description. Click the Detail button in the error dialog box to prompt for: overlaps the location of the Another project description, translated into Chinese that is, the imported project position overlaps another item.

B. One of the most likely causes of this error is that this project is under the working directory of Eclipse. Therefore, copying the project to another directory and then trying to import it will, in most cases, solve the problem.

Data address

Mysql-connector-net-6.3.9.msi:http://yunpan.cn/ckx77dgn6z9ex (Extract code: 80C7)

Android Development note "calling. NET WebService problems"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.