Мой товарищ по команде разработал приложение в Asp.NET
, а также написал в нем веб-службы. Мой руководитель сказал мне, что я звоню на эти службы с Android. Я много раз искал в Google, но я не могу понять, как вызвать веб-службы с Android.Как позвонить в веб-службы в android
Asp.Net Веб-сервисы:
"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; }
}
}
}
Как я могу назвать эти услуги? Любые ссылки на учебники будут оценены.
Перед тем, как отправить вопрос, вам нужно копать некоторые документы, не так ли? – RobinHood
Да, у меня есть. http://www.codeproject.com/Articles/112381/Step-by-Step-Method-to-Access-Webservice-from-Andr http://www.c-sharpcorner.com/UploadFile/88b6e5/how -to-call-web-service-in-android-using-soap/ и другие документы, но не понимаем, что делать. – Alven