VS と C# の完全な初心者です。非常に単純なことから始めて、Web サービスをセットアップしようとしています。アイテムのコードが与えられると、アイテムの名前を (うまくいけば) 返すクラスを書くことができました。これを実装してWebから呼び出せるようにしたいのですが、パラメータの取得方法がわかりません。アイデアは、http://myurl.com?ProdRef=XYZを持ち、製品 XYZ の名前を返すことです。
撃たないでください。これは C# と VS での私の最初の試みです。
編集:作業コード(誰に役立つか)
クラスコード:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for Class1
/// </summary>
class Product
{
public string ProdRef {get; set; }
public string ProdName{get; set; }
public static string GetLabel(string ProdRef)
{
//
// create a new SqlConnection object with the appropriate connection string
SqlConnection sqlConn = new SqlConnection("Data Source=ssss;Initial Catalog=ccccc;Persist Security Info=True;User ID=uuu;Password=pppp;Network Library=dbmssocn");
// open the connection
sqlConn.Open();
// create the command object
SqlCommand sqlComm = new SqlCommand("select libelle from dbo.vwArticlesPerm WHERE Ref = '" + ProdRef + "'", sqlConn);
string strResult = (string)sqlComm.ExecuteScalar();
// close the connection
sqlConn.Close();
return strResult;
}
}
Web サービス コード:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://xxxxx.lu/clientwebserv")]
[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 WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string GetName(string prName) {
return Product.GetLabel(prName);
}
}