2013-03-19 232 views
0

我創建的Web服務:調用Web服務

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 [email protected] and [email protected]", 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服務在另一個設備上工作,我該怎麼做?

+0

ASMX是一項傳統技術,不應該用於新開發。 WCF應該用於Web服務客戶端和服務器的所有新開發。一個暗示:微軟已經在MSDN上退役了[ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads)。 – 2013-03-19 19:18:41

回答

2

該端口專門用於Visual Studio - 它是Cassini或IIS Express,僅用於調試目的,不適用於現場製作工作。當你準備好發佈你的服務時,它可能會進入常規永久端口(大概80)的IIS中。一旦它在那裏,它將始終可供您的客戶打電話。

將服務發佈到IIS後,您只需更新客戶端的配置文件以指向真正的永久URL。

+0

你的意思是我應該在遠程主機上發佈我的web服務 – user1045265 2013-03-19 19:52:35

+0

是的,任何帶有IIS的服務器。但它不一定是一個不同的服務器 - 您可以將您的Web服務應用程序與您的Web應用程序放在同一個服務器上,只需在不同的虛擬目錄或網站中即可。 – 2013-03-19 19:58:34

+0

非常感謝 – user1045265 2013-03-19 20:02:22