我创建了网络服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
namespace MemberWebService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 Service1 : System.Web.Services.WebService
{
[WebMethod]
public DataSet GetMemberData(string memberId, string thirdName)
{
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Healthy;Integrated Security=TRUE");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = new SqlCommand("SELECT * FROM MemberMaster WHERE MemberId=@MemberId and ThirdName=@ThirdName", cn);
da.SelectCommand.Parameters.Add("@MemberId", SqlDbType.NVarChar).Value = memberId;
da.SelectCommand.Parameters.Add("@ThirdName", SqlDbType.NVarChar).Value = thirdName;
ds.Clear();
da.Fill(ds);
return ds;
}
}
}
当我运行它时,这是链接:
http://localhost:19722/Service1.asmx
它工作正常。
如果我在 asp.net 中调用它作为 web 参考它可以正常工作,直到服务器端口打开如果我关闭端口 asp.net 页面看不到 web 服务,那么我该如何解决问题,如果我想这样做Web 服务在另一台设备上工作我该怎么做?