如何在Windows Smart Phone 6中使用WebService?
我正在 .Net 3.5 Framework 中使用 C# 开发一款 Windows Smart Phone - 6 应用程序。我使用 ASP.Net Web 服务应用程序 3.5 创建了一个 Web 服务项目。在这个 Webservice 项目中,我定义了 Service1.asmx。现在我想在单击按钮时调用 Webmethod“HelloWorld”。这是代码。
Service1.asmx
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
和按钮单击事件
private void button1_Click(object sender, EventArgs e)
{
WebService1.Service1 myService = new WebService1.Service1();
string str = myService.HelloWorld();
}
我在这条线上遇到错误
WebService1.Service1 myService = new WebService1.Service1();
请给我指导,因为我对此很陌生。
提前致谢
Pratik Bhatt
I am Developing one Windows Smart Phone - 6 Application using C# in .Net 3.5 Framework. And I have created one Webservice project using ASP.Net Web Service Application 3.5. Into this Webservice project I have define Service1.asmx. Now I would like to call Webmethod "HelloWorld" on Button Click. Here is code.
Service1.asmx
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
And Button Click Event
private void button1_Click(object sender, EventArgs e)
{
WebService1.Service1 myService = new WebService1.Service1();
string str = myService.HelloWorld();
}
I am Getting Error On This Line
WebService1.Service1 myService = new WebService1.Service1();
Please Give Me Guidance As I am Very New In This.
Thanks In Advance
Pratik Bhatt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Visual Studio 中的添加 Web 引用对话框并将它们指向您的托管服务。该对话框根据生成的 WSDL 创建使用客户端。
您的方法不起作用,因为托管 Web 服务和使用 Web 服务使用一组不同的类。
Use the add web reference dialog from visual studio and point them to your hosted service. The dialog creates the consuming client based on the generated WSDL.
Your approach doesn't work because hosting a webservice and consuming one uses a different set of classes.
问题解决了。
发生错误是因为智能设备模拟器没有互联网(网络)的访问权限,因此您必须安装 Microsoft Active Sync 才能将模拟器连接到网络
感谢 Ralf Ehlert 的建议......
Problem Solved.
Error Was Occurring Because The Smart Device Emulator has No Access Permission for internet(network)so you have to install Microsoft Active Sync to connect emulator to network
Thanks Ralf Ehlert For Suggesting.....