0

大家好,下面是我想使用的 WebService 类(我写的)。问题是我不太确定如何使用它。我有一个 WinForm 通过另一个实例连接到数据库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;
    }

}

我想调用getXmlCompanyCompany.aspx.cs 文件中的任何其他方法,就像调用任何其他方法一样——如果可能的话

亲切的问候

马库斯

4

1 回答 1

1

当您调试 Web 服务时,如果一切正常,您将在那里看到您的 Web 方法列表。现在,在浏览器中复制 url,转到需要使用它的项目,添加 web 引用并将 url 过去。它将查看并显示您的 web 服务。

此外,您可以考虑在 IIS 中托管您的 Web 服务,这样您就不必每次都运行调试。

于 2012-05-18T21:10:36.743 回答