0

我的队友在其中开发了一个应用程序,Asp.NET并在其中编写了 Web 服务。我的主管告诉我从 Android 调用这些服务。我在 Google 上进行了广泛搜索,但我无法理解如何从 Android 调用 Web 服务。

Asp.Net Web 服务有:

“GenerateTreeFromXMLWebService.asmx”网络服务类

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Xml.Linq;

namespace UnitTestWebApp
{
    /// <summary>
    /// Summary description for GenerateTreeFromXMLWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class GenerateTreeFromXMLWebService : System.Web.Services.WebService
    {
        Node node = new Node();

        XDocument xDoc = new XDocument();
        string xml;   //to save the xml data value

        // this method is for reading xml from file and storing it in a string
        public GenerateTreeFromXMLWebService()
        {
            xml = File.ReadAllText("E:\\Unit Testing\\AdWordsTestsnew.xml");
            xDoc = XDocument.Parse(xml);
        }

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        //this method is used to separate parent nodes with their child from xml file
        [WebMethod]
        public Node generateXMLTree()
        {

            XElement rootElement = xDoc.Element("Node");



            node.ResultName = rootElement.Attribute("result").Value;
            node.MethodName = rootElement.Attribute("name").Value;

            if (rootElement.HasElements)
                generateChild(node, rootElement);

            return node;

        }
        //this method is used for making child nodes
        void generateChild(Node node, XElement rootElement)
        {

            foreach (XElement a in rootElement.Elements("Node"))
            {
                Node K = new Node();
                K.ResultName = a.Attribute("result").Value;
                K.MethodName = a.Attribute("name").Value;

                node.AddChild(K);
                //this recursion is for making inner child node of the child functions
                generateChild(K, a);
            }
        }

    }
}

Service.cs 类:

namespace GenerateTree
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}

我如何调用这些服务?任何教程链接将不胜感激。

4

1 回答 1

0

如果是 .net soap-web-service 那么这个 url 可以帮助你。

http://gafurbabu.wordpress.com/2012/05/28/how-to-call-soap-web-service-with-android-only-soap-service-not-rest-service/

谢谢。

于 2013-04-10T07:12:20.977 回答