Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your exception was actually complaining about their being a conflict between these two methods on the <code>Profile</code> controller:</p> <ul> <li>sendpaycheck(string)</li> <li>sendmail(string)</li> </ul> <p>Not the Get and Get(?); although this would also be an issue. </p> <p>Really, when carrying out RPC actions that make changes or trigger actions you should use the POST verb. By doing this your routing issues mentioned above should be resolved.</p> <p><strong>Updated</strong></p> <p>Have you considered a more resource centric approach to your problem? In all cases here the resource is "Profile" and it appears to have a unique id of x. It appears to also have two other possible unique id's email and ssn?</p> <p>If these were acceptable URL's to you</p> <pre><code>http://localhost/api/profile http://localhost/api/profile/x http://localhost/api/profile/?email=myemail@x.com http://localhost/api/profile/?ssn=x </code></pre> <p>you could use:</p> <pre><code>public class ProfileController : ApiController { public string Get(int id) { return string.Format("http://localhost/api/profile/{0}", id); } public string Get([FromUri] string email = null, [FromUri] int? ssn = null) { if (!string.IsNullOrEmpty(email)) { return string.Format("http://localhost/api/profile/?email={0}", email); } if (ssn.HasValue) { return string.Format("http://localhost/api/profile/?ssn={0}", ssn.Value); } return "http://localhost/api/profile"; } } </code></pre> <p>With just the standard webapi routing:</p> <pre><code> config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } </code></pre> <p><strong>But</strong></p> <p>If you did want to carry on with /email and /ssn you may have issues with the email... specifically with the "." in the email address and this can confuse the routing engine... for this to work you must put a trailing slash i.e. <code>http://localhost/api/profile/email/me@me.com/</code> I think you will find <code>http://localhost/api/profile/email/me@me.com</code> wont work. </p> <p>This supports:</p> <pre><code>http://localhost/api/profile http://localhost/api/profile/x http://localhost/api/profile/email/myemail@x.com/ http://localhost/api/profile/ssn/x </code></pre> <p>I would try this and use (NB. the use of the name <strong>rpcId</strong> to differentiate the routes):</p> <pre><code>public class ProfileController : ApiController { public string Get(int id) { return string.Format("http://localhost/api/profile/{0}", id); } public string Get() { return "http://localhost/api/profile"; } [HttpGet] public string Ssn(int rpcId) { return string.Format("http://localhost/api/profile/ssn/{0}", rpcId); } [HttpGet] public string Email(string rpcId) { return string.Format("http://localhost/api/profile/email/{0}", rpcId); } } </code></pre> <p>My routing would then be:</p> <pre><code> config.Routes.MapHttpRoute( name: "ProfileRestApi", routeTemplate: "api/profile/{id}", defaults: new { id = RouteParameter.Optional, Controller = "Profile" } ); config.Routes.MapHttpRoute( name: "PrfileRpcApi", routeTemplate: "api/profile/{action}/{rpcId}", defaults: new { Controller = "Profile" } ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload