私は新しい開発者であり、this tutorialに従うことでC#でWebサービスを開発しようとしています。そのチュートリアルで説明したように、私はすべてをした、しかし、私は、Northwindデータベースからデータを取得していないと私は起動ボタン押したときに、私は以下のページを持って:あなたはチュートリアルで見るよう このWebサービスはどのように動作させるのですか?
を、私がやりましたweb.configファイルにConnectionStringを追加しないでください。私はそれをすべきか?
マイコード:
public class WSGetCustomerCountryWise : System.Web.Services.WebService
{
public WSGetCustomerCountryWise()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod(Description = "It will generate Customer List, CountryWise")]
public System.Xml.XmlElement
GetCustomerCountryWise(string sCountry)
{
string sConn = ConfigurationManager.ConnectionStrings["connStr"].ToString();
string sSQL = "select CustomerId, CompanyName, ContactTitle, City from Customers where country = '"+sCountry+"'";
SqlConnection connCustomer = new SqlConnection(sConn);
DataSet dsCustomer = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(sSQL, sConn);
sda.Fill(dsCustomer);
System.Xml.XmlDataDocument xdd = new System.Xml.XmlDataDocument(dsCustomer);
System.Xml.XmlElement docElem = xdd.DocumentElement;
return docElem;
}
}
"古い"従来のASMX Webサービスの代わりに** WCF **を学ぶことを強くお勧めします。 –
@marc_s:必ずしもそうではありません - シンプルな仕事のために、私はまだハンドリングがはるかに簡単で(特に初心者の方でもモノでも)、「新しいもの」が必要ない場合はそれを作る必要はないので、「古いもの」を好むもっと複雑な場合は... – ChrFin
@chrfinマイクロソフトでは、ASP.NET Webサービスの代わりにWCFの使用を推奨しています。 [リンク](http://msdn.microsoft.com/en-us/library/t745kdsh.aspx)を参照してください。また、ASMXスタイルのWCFサービスの簡単な例もあります。 ;)(おそらく、AJAX対応のWCFサービス、例えば[link](http://msdn.microsoft.com/en-us/library/bb924552.aspx) – Nicholas