如何在Windows Phone 7应用程序中使用webservice [英] How to use webservice in Windows Phone 7 application

查看:95
本文介绍了如何在Windows Phone 7应用程序中使用webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发Windows Phone 7的应用程序。我对webservices了解不多。

有一个我想要使用的web服务,其形式为http://something.wsdl

这个服务托管一组方法,我是知道。



我已将此作为服务参考添加到我的WP7项目中。但我无法访问任何方法。我错过了什么吗?请帮助



谢谢

I am currently developing an application for Windows Phone 7. I do not know much about webservices.
There is a webservice that i want to use which is in the form http://"something".wsdl
This service hosts a set of methods, which I am aware of.

I have added this as Service Reference to my WP7 project. But I am not able to access any of the methods. Am I missing something? Please help

Thank you

推荐答案

现在我要你做几件事并回来:



1.在某些Windows控制台应用程序中检查此Web服务,看看您是否能够访问所需的方法



2.现在,当您将Web服务添加到WP7项目时,是否在该参考Web服务程序集上看到任何损坏的链接/错误链接/不可用参考图像。如果不是只是尝试在对象浏览器中看到该Web服务程序集是否显示方法。



3.您是否能够为Web服务类创建对象想用吗?
Now I want you to do few things and come back:

1. Check this web service in some windows console application and see if you are able to access the required methods

2. Now when you add the web service to your WP7 project, is there any broken link/wrong link/unavailable reference image seen on that refereed web service assembly. If not just try to see in the Object Browser if that web service assembly is showing the methods.

3. Have you able to create object for the web service class you want to use ?


试试这个



与Windows Mobile / Windows Phone的Web服务通信 [ ^ ]


看起来男人我不知道了解因为我需要查看代码但是让我帮助你:



第一用户WCF它比网络服务更专业,也是一种网络通过右键单击您的解决方案,您可以做到这一点 - >添加 - >新项目 - >转到Visual C#下的Web并添加新的asp.net空Web应用程序



第二次 - 右键单击​​这个新的Web应用程序 - >添加 - > New Item也会在visual C#下进入web并选择WCF服务并添加它并且不要忘记构建它转到你的手机项目右键单击添加服务引用单击Discover后文本框地址将填充路径WCF自动然后按确定但不要忘记当您在WCF中更改任何内容时,您必须在服务引用右键单击更新下的youServiceNameservicereference上更新服务



3rd-在Iservice1.CS中你必须按如下方式添加你的课程:



look man i don't understand becuase i need to see the code but let me help you:

1st- user WCF it is more professional than web-service and also it is a kind of web service you can do that by right click on your solution -> Add --> New Project -> go to Web under Visual C# and add new asp.net empty web application

2nd- right click on this new web app -> add -> New Item also go to web under visual C# and choose WCF Service and add it and don'y forget to build it the go to your phone project right click add service reference click Discover after the the text box address will be filled with the path of the WCF automatically then press ok but dont forget when you change anything in the WCF you have to update the service by right on youServiceNameservicereference under service reference right click update

3rd- in the Iservice1.CS you have to add your class as follows :

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetItemInfo(string Category);//this is your function
    }
    [DataContract]
    public class Items
    {
        public string ID { get; set; }

        public string Category { get; set; }

        public string Info { get; set; }

        public int Quantity { get; set; }

        public string Mark { get; set; }

        public int Price { get; set; }
    }



并在IService1.svc.cs中添加函数ass如下:


and in the IService1.svc.cs add the function ass follows:

public class Service1 : IService1
    {
        string connection = ConfigurationManager.ConnectionStrings["Connection"].ToString();
        public string GetItemInfo(string Category)
        {
            Items items = new Items();
            SqlDataReader reader = null;
            SqlCommand cmd = new SqlCommand("select top(1) ID, Category, Info, Mark, Quantity, Price from item where category ='" + Category + "'");
            SqlConnection conn = new SqlConnection(connection);
            conn.Open();
            cmd.Connection = conn;
            reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                items = new Items();
                items.ID = (string)reader["ID"];
                items.Category = reader["Category"].ToString().Trim();
                items.Info = reader["info"].ToString().Trim();
                items.Mark = reader["Mark"].ToString().Trim();
                items.Quantity = Convert.ToInt16(reader["Quantity"]);
                items.Price = Convert.ToInt16(reader["Price"]);
            }
            conn.Close();
            return items.Info;
        }
    }





4-在您的页面背后的代码中使用函数ass:





4th- in the code behind of your page use the function ass follows:

private void btnFind_Click(object sender, RoutedEventArgs e)
        {
            Service1Client service = new Service1Client();
            service.GetItemInfoAsync(txt1.Text);
            service.GetItemInfoCompleted += new EventHandler<GetItemInfoCompletedEventArgs>(service_GetItemInfoCompleted);

        }

        void service_GetItemInfoCompleted(object sender, GetItemInfoCompletedEventArgs e)
        {
            txb1.Text = e.Result;
        }









别忘了什么时候你在服务中进行更改会更新移动应用程序中的服务引用。

最好的问候,如果有帮助,请不要忘记投票。





don't forget when you make changes in the service update the service reference in the mobile application.
best regards and don't forget to vote if this help you.


这篇关于如何在Windows Phone 7应用程序中使用webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆