c#在WebService如何添加类

cehcueu 2009-05-22 04:42:57


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml.Serialization;
namespace indexMain1
{
/// <summary>
/// WSTruck_Short 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WSTruck_Short : System.Web.Services.WebService
{

我想在这里添加一个类,让用户使用这个类。
在方法中返回这个类的数组。
[WebMethod]
public string leifanhui(leiname [] c)
{
return "Hello World";
}


}
}

...全文
299 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
uowzd01 2009-05-22
  • 打赏
  • 举报
回复
直接在类里面定义另一个类,然后来调用它。

public class WSTruck_Short : System.Web.Services.WebService
{
// 我想在这里添加一个类,让用户使用这个类。
// 在方法中返回这个类的数组。
public class PersonInfo
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}

[WebMethod]
public string leifanhui(leiname [] c)
{
PersonInfo p = new PersonInfo();
p.Name = "Ken";
return "Hello World" + p.Name;
}
}
zhensoft163 2009-05-22
  • 打赏
  • 举报
回复
那你就直接在这添加的啊
跟HollowWorld是一样的啊
tianhuo_soft 2009-05-22
  • 打赏
  • 举报
回复
路过
c02645 2009-05-22
  • 打赏
  • 举报
回复
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/getValidate"
this.Invoke("getValidate"



getValidate这个要和asmx的对应

new object[] {userName,password}

参数对应
c02645 2009-05-22
  • 打赏
  • 举报
回复

/// <summary>
/// 主接口
/// </summary>
[System.Web.Services.WebServiceBindingAttribute(Name = "userValidateSoap", Namespace = "http://tempuri.org/")]
public class serviceClass : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public serviceClass()
{
this.Url = "http://192.168.1.90:800/userValidate.asmx";
}

#region 用户验证和登录
/// <summary>
/// 判断用户是否要验证
/// </summary>
/// <param name="userName">用户名</param>
/// <returns></returns>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/getValidate", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool getValidate(string userName)
{
try
{
object[] results = this.Invoke("getValidate", new object[] {
userName});
return (bool)(results[0]);
}
catch { return false; }
}
/// <summary>
/// 验证
/// </summary>
/// <param name="key">keyNumber</param>
/// <param name="userName">用户名</param>
/// <returns></returns>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/goUserKey", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool goUserKey(string key, string userName)
{
try
{
object[] results = this.Invoke("goUserKey", new object[] {
key,userName});
return (bool)(results[0]);
}
catch { return false; }
}
/// <summary>
/// 用户登录
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="passWord">密码</param>
/// <returns></returns>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/loginUser", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string[] loginUser(string userName, string passWord)
{
try
{
object[] results = this.Invoke("loginUser", new object[] {
userName,passWord});
return (string[])(results[0]);
}
catch { return null; }
}
#endregion

#region 验证升级版本
/// <summary>
/// 验证升级版本
/// </summary>
/// <param name="edition">当前版本</param>
/// <returns></returns>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/getUpdateName", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string getUpdateName(string edition)
{
try
{
object[] results = this.Invoke("getUpdateName", new object[] { edition });
return (string)(results[0]);
}
catch { return null; }
}
/// <summary>
/// 验证升级版本
/// </summary>
/// <returns></returns>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/getEdition", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string getEdition()
{
try
{
object[] results = this.Invoke("getEdition", new object[] {
});
return (string)(results[0]);
}
catch { return null; }
}
#endregion



/// <summary>
/// 下载小文件
/// </summary>
/// <param name="FileName">文件名</param>
/// <returns></returns>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/downloadFile", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public byte[] downloadFile(string FileName)
{
try
{
object[] results = this.Invoke("downloadFile", new object[] {
FileName});
return (byte[])(results[0]);
}
catch { return null; }
}
}
cehcueu 2009-05-22
  • 打赏
  • 举报
回复
UP

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧