客户端可以正常调用web service自带生成的HelloWorld()方法,我自己在服务端写了个方法,在客户端调用时候却报错。本人刚接触C#,希望大家给点指导。、
web service代码:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;namespace WebService
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
public Service1()
{ } [WebMethod]
public string HelloWorld()
{
return "HelloWorld!";
}
[WebMethod]
public string Show(string yourname)
{ return "http://www.ourfly.com"+"欢迎"+yourname; }
}
}
客户端代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Web;
using System.Web.Services;
using WebService;namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
mysoap.Service1 Service = new mysoap.Service1();
string s = Service.HelloWorld();
Console.WriteLine(s); Console.ReadLine(); }
}
}调用Show方法时候报错,
mysoap.Service1 Service = new mysoap.Service1();
string s = Service.Show("aa");
web service代码:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;namespace WebService
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
public Service1()
{ } [WebMethod]
public string HelloWorld()
{
return "HelloWorld!";
}
[WebMethod]
public string Show(string yourname)
{ return "http://www.ourfly.com"+"欢迎"+yourname; }
}
}
客户端代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Web;
using System.Web.Services;
using WebService;namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
mysoap.Service1 Service = new mysoap.Service1();
string s = Service.HelloWorld();
Console.WriteLine(s); Console.ReadLine(); }
}
}调用Show方法时候报错,
mysoap.Service1 Service = new mysoap.Service1();
string s = Service.Show("aa");
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货