C# 如何使用Web服务
嗨,下面是一个我想使用的WebService类(我写的)。问题是我不太确定如何使用它。我有一个WinForm,它通过另一个C# 如何使用Web服务,c#,asp.net,database,C#,Asp.net,Database,嗨,下面是一个我想使用的WebService类(我写的)。问题是我不太确定如何使用它。我有一个WinForm,它通过另一个DataAccessObject实例连接到数据库 用户必须能够单击按钮打开表单的网站版本,并从中修改数据库 问题是我不知道如何使用该服务来做到这一点 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; us
DataAccessObject
实例连接到数据库
用户必须能够单击按钮打开表单的网站版本,并从中修改数据库
问题是我不知道如何使用该服务来做到这一点
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml.Linq;
using System.Configuration;
/// <summary>
/// Summary description for DataManager
/// </summary>
[WebService(Namespace = "/201103578Site//Default.aspx")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 DataManager : System.Web.Services.WebService
{
XElement[] xmlCompany = null;
XElement[] xmlCandidate = null;
XElement[] xmlQualification = null;
public DataManager ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
DataAccessObject.DataAccessObject daoDataBase = new DataAccessObject.DataAccessObject(ConfigurationManager.ConnectionStrings[1].ToString());
daoDataBase.openConnection();
xmlCompany = daoDataBase.sqlSelectCompany(new SQL.SqlImplementation(), "Select * From Company");
xmlCandidate = daoDataBase.sqlSelectCandidate(new SQL.SqlImplementation(), "Select * From Candidate");
xmlQualification = daoDataBase.sqlSelectQualification(new SQL.SqlImplementation(), "Select * From Qualification");
daoDataBase.closeConnection();
}
[WebMethod]
public XElement[] getXmlCompany()
{
return xmlCompany;
}
[WebMethod]
public XElement[] getXmlCandidate()
{
return xmlCandidate;
}
[WebMethod]
public XElement[] getXmlQualification()
{
return xmlQualification;
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Services;
使用System.Xml.Linq;
使用系统配置;
///
///DataManager的摘要说明
///
[WebService(Namespace=“/201103578Site//Default.aspx”)]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
//要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
//[System.Web.Script.Services.ScriptService]
公共类数据管理器:System.Web.Services.WebService
{
XElement[]xmlCompany=null;
XElement[]xmlCandidate=null;
XElement[]xmlQualification=null;
公共数据管理器()
{
//如果使用设计的组件,请取消注释以下行
//初始化组件();
DataAccessObject.DataAccessObject daoDataBase=新的DataAccessObject.DataAccessObject(ConfigurationManager.ConnectionString[1].ToString());
daoDataBase.openConnection();
xmlCompany=daoDataBase.sqlSelectCompany(新的SQL.SqlImplementation(),“选择*来自公司”);
xmlCandidate=daoDataBase.sqlSelectCandidate(new SQL.SqlImplementation(),“Select*From Candidate”);
xmlQualification=daoDataBase.sqlSelectQualification(新的SQL.SqlImplementation(),“从限定中选择*);
daoDataBase.closeConnection();
}
[网络方法]
公共XElement[]getXmlCompany()
{
返回公司;
}
[网络方法]
公共XElement[]getXmlCandidate()
{
返回候选人;
}
[网络方法]
公共XElement[]getXmlQualification()
{
退货资格;
}
}
我想调用getXmlCompany
和Company.aspx.cs文件中的任何其他方法,就像调用任何其他方法一样-如果可能的话
问候
Markus调试web服务时,如果一切正常,您将在那里看到web方法的列表。现在,在浏览器中复制url,转到需要使用它的项目,添加web引用并在中跳过url。它将查看并显示您的Webservice
此外,您还可以研究在IIS中托管Web服务,这样就不必每次都运行调试 您需要在调试器中启动web服务项目,然后转到将使用它的项目并选择添加web引用。