Thursday 15 March 2012

Optional parameter in UriTemplate in WCF -


I used the signal and provided a default value, so that when the user created a viral sub-directory, I made the impression I've been listing that all the accessories listed mean it works. [WebInvoke (UriTemplate = "GetStuff / {type = all}" ... ... IEnumerable & lt; Content & gt; GetStuff (string type); default is tap and I want to send it in a real value In particular, I have set my heart on String.Empty . However, I have found that the following does not work.The position of the server side is empty string (< Em> ... where in 'Type' (ColName, '', 'all') ).

  [WebInvoke (UriTemplate = "GetStuff / {type =   

What to do?

"post-text" itemprop = "text">

you actually empty in a URITemplate You can not have the default value, but you can have something that means the default value, and you can change that location in the actual default value you want, as shown below / P>

  public square StackOverflow_ 17251719 {const string DefaultValueMarker = "___DEFAULT_VALUE___"; Const String ActualDefaultValue = ""; [Service contract] Public class service {[WebEnvoc (EurTemplate = "gatestaff / {type =" + default wolver + "}", response format = web message format. Json)] public inenemable & lt; String & gt; GetStuff (string type) {if (type == DefaultValueMarker) {type = ActualDefaultValue; } Yield returns type; }} Public Static Zero SendBodylessPostRequest (String Yuri) {HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create (Yuri); Req.method = "POST"; Req.ContentType = "App / Jason"; Req.GetRequestStream () off () .; // respite a request body HttpWebResponse; Try {resp = (HttpWebResponse) req.GetResponse (); } Grip (WebExpress E) {resp = (HTTP Webbense) e. response; } Console.WriteLine ("HTTP / {0} {1} {2}", resp.ProtocolVersion, (int) resp.StatusCode, resp.StatusDescription); Foreach (in string header name resp.Headers.AllKeys) {Console.WriteLine ("{0}: {1}", header name, resp.Headers [header name]); } Console. Wrightite (); Stream respStream = resp.GetResponseStream (); Console.promotion (new stream reader (reststream). Read-end ()); Console.WriteLine (); Console.lightline ("* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *"); Console.WriteLine (); } Public static zero testing () {string baseAddress = "http: //" + Environment. Mykinnam + ": 8000 / service"; WebServiceHost host = New WebServiceHost (type (service), new URI (BaseEdrace)); Host.Open (); Console.light line ("host opened"); SendBodylessPostRequest (baseadder + "/ gatestaff / non default"); SendBodylessPostRequest (baseadder + "/ gatestuff"); Console Type ("Press ENTER to close the host"); Console.ReadLine (); Host.Close (); }}    

No comments:

Post a Comment