Android calls Asp.net WebService

Source: Internet
Author: User
Public soapprimitive detail; // namespace Private Static final string namespace = "http://tempuri.org/"; // WebService address Private Static string webserviceurl = "http://www.xxx.com/Services/xxx.asmx "; // here is the namespace + method name Private Static string soap_action = "http://tempuri.org/GetComapnyXML"; // URL Private Static final string WSDL = "http://www.xxx.com/Services/xxxx.asmx? WSDL "; private onclicklistener calc = new onclicklistener () {@ overridepublic void onclick (view V) {// The first parameter is the namespace. The second parameter is the method to call soapobject request = new soapobject (namespace, "getcomapnyxml");/* The first parameter passing, parameter names do not have to be consistent with WebService parameters, but must be requested in order. addproperty ("startcount", "1"); Request. addproperty ("endcount", "2"); Request. addproperty ("jobcount", "2"); * // * second parameter */propertyinfo Pi = new propertyinfo (); Pi. setname ("startcount"); Pi. setvalue ("1"); Request. addproperty (PI); Pi = new propertyinfo (); Pi. setname ("endcount"); Pi. setvalue ("2"); Request. addproperty (PI); Pi = new propertyinfo (); Pi. setname ("jobcount"); Pi. setvalue ("2"); Request. addproperty (PI); element [] header = new element [1]; header [0] = new element (). createelement (namespace, "companytoken"); // If there are multiple elements, follow the same method below: Element Pwd = new element (). createelement (namespace, "companykey"); PWD. addchild (node. text, "password"); header [0]. addchild (node. element, PWD); soapserializationenvelope envelope = new soapserializationenvelope (soapenvelope. ver11); envelope. headerout = header; envelope. bodyout = request; envelope. DOTNET = true; envelope. setoutputsoapobject (request); // httptransportse ht = new httptransportse (webserviceurl); androidhttptransport httptranstation = new androidhttptransport (WSDL); try {/HT. call (soap_action, envelope); httptranstation. call (soap_action, envelope); detail = (soapprimitive) envelope. getresponse (); textconten. settext (detail. tostring ();} catch (ioexception e) {// todo auto-generated Catch Block // E. printstacktrace (); log. E (this. tostring (), E. tostring (); // toast. maketext (webservicetestactivity. this, // "file stream error" + E. tostring (), toast. length_long);} catch (xmlpullparserexception e) {// todo auto-generated catch blocke. printstacktrace (); // toast. maketext (webservicetestactivity. this, // "XML file stream error" + E. tostring (), toast. length_long);} catch (exception e) {// todo: handle exception // toast. maketext (webservicetestactivity. this, // "error" + E. tostring (), toast. length_long); log. E (this. tostring (), E. tostring ());}}};

 
<? XML version = "1.0" encoding = "UTF-8"?> <Soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/soap/envelope/"> <soap: header> <companytoken xmlns = "http://tempuri.org/"> <companykey> string </companykey> </companytoken> </soap: Header> <soap: body> <getcomapnyxml xmlns = "http://tempuri.org/"> <startcount> string </startcount> <endcount> string </endcount> <jobcount> string </jobcount> </getcomapnyxml> </soap: body> </soap: envelope>

First download http://code.google.com/p/ksoap2-android/downloads/list? Can = 1 & Q = & colspec = filename + Summary + uploaded + releasedate + size + downloadcount

Ksoap2-android-assembly-2.4-jar-with-dependencies.jar

Right-click Project Properties --> JAVA build path --> libraries to add a jar package

Remember to add the Internet access permission to the androidmanifest. xml file.

<Uses-Permission Android: Name = "android. Permission. Internet"> </uses-Permission>

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.