I created a WCF service in C #. And I publish it successful. Now I want to pass the parameters in the URL and the data in WCF json is returning back to format.but I am not able to answer any of the answer. So I can help you with how I'm trying to add parameters at the end of the URL.
IwcfDataService.cs
namespace RestWCFService {[ServiceContract] Public Interface IWcfDataService {[OperationContract] [WebInvoke (Method = "GET", ResponseFormat = WebMessageFormat.Json, Bodystyle = WebMessageBodyStyle.Wrapped, Uretemplate = "search? Keyword = {keyword}")] list & lt; String & gt; Search (string keyword); } [Data Contract] Public Sector Information {[Datamember] Public String Entertext {get; Set; } [Database] Public string URL {Receive; Set; } [Datamember] get public string title {get; Set; }}}
WcfDataService.svc.cs
namespace RestWCFService {public class WCFDataService : IWcfDataService {Public listing & lt; String & gt; Search (string keyword) {SqlConnection sql_Search; Sql_Search = New SqlConnection ("Data Source = FPBLWD0310; Initial Catalog = Support; Integrated Security = True"); Sql_Search.Open (); SqlCommand SelectCommand = new SqlCommand ('+ keyword + "%"%) ", sql_Search keyword, URLNAME, where the title from finalCrawler (select" like keyword "); SelectCommand.ExecuteNonQuery (); SqlDataAdapter SQLAd = New SqlDataAdapter (SelectCommand); Read SqlDataReader = SelectCommand.ExecuteReader (); Extension d = faucet; & Lt; String & gt; ListDetail = New list & lt; String & gt; (); (Read.Read ()) {D = While new extensions {innerText = read ["keyword"] ToString (), URL = read ["URLNAME"]. ToString (), title = read ["title"]. ToString ()}; Var javaScriptSerializer = New system. Web.Script.Serialization.JavaScriptSerializer (); String jsonString = javascriptSerializer.Serialize (D); ListDetail.Add (jsonString); } Sql_Search.Close (); Return listDital; }
url , you can tell me how I add parameters to the end of the URL, I get the result
http: // localhost: 8434 / wcfDataService.svc? SingleWsdl
Just use this to create your url parameters:
url + = String.Format ("& amp; TABNAME = {0}", HttpUtility.UrlEncode (TABNAME));
No comments:
Post a Comment