|
HI, I'm trying to get work my Web Api application to work with url extension (http:<url>/contacts.json like in the ContactManager sample). I put the same code in WebApiConfig.cs [code] config.Formatte rs.JsonFormatte r.AddUriPathExt ensionMapping(" json","applicat ion/json"); config.Formatte rs.XmlFormatter .AddUriPathExte nsionMapping("x ml","applicatio n/xml"); config.Routes.M apHttpRoute( name:"Controlle rWithExt", routeTemplate:" api/{controller }.{ext}"); config.Routes.M apHttpRoute( name:"IdWithExt ", routeTemplate:" api/{controller }/{id}.{ext}"); [/code] But I got 404 Not found result I try the ContactManager sample and it work fine. The only difference between my project and the sample is the version of the packages. If someone can say me what's i'm doing wrong. Regards
Hi , Is contact management possible on windows store apps with XAML/C#.(I want to create a contact,delete a contact and modify a contact.). If possible how to do it. Can u please help me on this. I had found only contact picker sample . Thank u syamala.
I have the following scenario. My customer calls my web api service in java using POST method passing me XML structure as an input parameter. See below: <?xml version="1.0" encoding="UTF-8"?> <rest-client version="2.4"> <request> <http-version>1 .1</http-versio n> <http-follow-re directs>false</ http-follow-red irects> <URL>http://XXX XXXXX/getCoupon .do</URL> <method>POST</m ethod> <auth-methods>B ASIC</auth-meth ods> <auth-preemptiv e>false</auth-p reemptive> <auth-username> username</auth- username><auth- password>passwo rd</auth-passwo rd> <body content-type="a pplication/xml" charset="UTF-8" > <?xml version="1.0" encoding="UTF-8 " standalone="yes "?><GetPh armacyNotesRequ est> <RequestID&g t;TestRequestId 1</RequestID > <DocumentID& gt;625</Docu mentID></ GetPharmacyNote sRequest> </body> </request> </rest-client> My task is to authenticate their username and password against my database before returning anything back. I have tried to figure out how to read auth-username and auth-password parameters but I came up short. Please point me in the right direction. Thanks
Assuming you are hosting your web API in IIS you probably want an authentication module that handles basic auth using the ASP.NET Membership provider as the identity store. We don't provide such an authentication module out of the box, but you could take a look at one implemented by the community (ex http://custombasicauth.codeple x.com/).
I'd suggest authenticating them once and setting a session ID that expires after a short period, and have them pass the session ID for every call they need to return data. Store the session ID, and time and validate against that for every call. Set it to expire, have them re-auth and repeat.
I've updated Daniel sample to make it work with ASP.NET Forms Auth from a web client and from the Windows Store app, here is the magic to login in AddContactsGroups method : HttpResponseMes sage response = null; Uri address = new Uri(@"http://lo calhost/"); CookieContainer cookieJar = new CookieContainer (); HttpClientHandl er handler = new HttpClientHandl er() { CookieContainer = cookieJar }; handler.UseCook ies = true; handler.UseDefa ultCredentials = false; HttpClient client = new HttpClient(hand ler as HttpMessageHand ler) { BaseAddress = address }; response = await client.GetAsync ("Account/Login "); String form = await response.Conten t.ReadAsStringA sync(); int index = form.IndexOf("_ _RequestVerific ationToken"); String token = form.Substring( index + 49,172); HttpContent content = new FormUrlEncodedC ontent(new[] { new KeyValuePair<st ring, string>("__Requ estVerification Token", token), new KeyValuePair<st ring, string>("UserNa me", "cedric"), new KeyValuePair<st ring, string>("Passwo rd", "cyberced"), new KeyValuePair<st ring, string>("Rememb erMe", "false") }); response = await client.PostAsyn c("Account/Logi n", content); response = await client.GetAsync ("api/contacts" ); Contact[] contacts = await response.Conten t.ReadAsAsync<C ontact[]>(); To secure your Api Controller method just add an Authorize attribute like this : [Queryable] [Authorize(Role s = "")] public IEnumerable<Con tact> Get() HTH
Hi Daniel, Can you explain your thought process behind the split between the API-REST controllers for the contact logic and the more traditional MVC style controllers for the account management logic? I also noticed the views for the account logic used razor control binding while the contact logic used knockout. Thanks, Josh
I have an existing database that stores all of my employees information for public viewing. Is there a way that I can leverage LDAP login for the login form so that a user can login and update their information?
Hi Daniel, After a clean install from Win 8 RTM and Visual Studio 2012 RTM the sample doesnt run. When will this be updated? Regards, Eric
When I start the app from the C# solution, it fails: Solution folders are not supported in this version of the application...".nuget" will be displayed as unavailable. Seems that there are different versions of C# express, but I'm not sure if that's the problem
The necessary .dll files needed are there already. How do I deploy it? Am I missing something?
Hi Daniel, Thanks for providing the sample. However I'm not able to get it to work even after installing SqlLocalDB.MSI and KB2544525. VS 2010 SP1 fails to load the ContactManagerContext-20120803 165354.MDF and after running the web site i get the following exception in the Ajax call: {"Message":"An error has occurred.", "ExceptionMessa ge":"The 'ObjectContent` 1' type failed to serialize the response body for content type 'application/js on; charset=utf-8'. ", "ExceptionType" :"System.Invali dOperationExcep tion", "StackTrace":nu ll, "InnerException ":{ "Message":"An error has occurred.", "ExceptionMessa ge":"Invalid value for key 'attachdbfilena me'.", "ExceptionType" :"System.Argume ntException", "StackTrace":" <omitted> I'm running the sample on Windows Server 2008 R2 x64. Would appreciate any help to get this up and running. I'm especially looking forward to seeing how the media type formatter works since i have a similar requirement in my project. Many thanks! Shardul.
I hit the very same problem running on Windows 8 Pro. Here's the full error output: {"Message":"An error has occurred.","ExceptionMessage": "The 'ObjectContent` 1' type failed to serialize the response body for content type 'application/js on; charset=utf-8'. ","ExceptionTyp e":"System.Inva lidOperationExc eption","StackT race":null,"Inn erException":{" Message":"An error has occurred.","Exc eptionMessage": "An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.","Exce ptionType":"Sys tem.Data.Provid erIncompatibleE xception","Stac kTrace":" at System.Data.Ent ity.ModelConfig uration.Utiliti es.DbProviderSe rvicesExtension s.GetProviderMa nifestTokenChec ked(DbProviderS ervices providerService s, DbConnection connection)\r\n at System.Data.Ent ity.DbModelBuil der.Build(DbCon nection providerConnect ion)\r\n at System.Data.Ent ity.Internal.La zyInternalConte xt.CreateModel( LazyInternalCon text internalContext )\r\n at System.Data.Ent ity.Internal.Re tryLazy`2.GetVa lue(TInput input)\r\n at System.Data.Ent ity.Internal.La zyInternalConte xt.InitializeCo ntext()\r\n at System.Data.Ent ity.Internal.In ternalContext.G etEntitySetAndB aseTypeForType( Type entityType)\r\n at System.Data.Ent ity.Internal.Li nq.InternalSet` 1.Initialize()\ r\n at System.Data.Ent ity.Internal.Li nq.InternalSet` 1.GetEnumerator ()\r\n at System.Linq.Enu merable.WhereSe lectEnumerableI terator`2.MoveN ext()\r\n at System.Collecti ons.Generic.Lis t`1..ctor(IEnum erable`1 collection)\r\n at System.Linq.Enu merable.ToList[ TSource](IEnume rable`1 source)\r\n at Newtonsoft.Json .Serialization. JsonArrayContra ct.CreateWrappe r(Object list)\r\n at Newtonsoft.Json .Serialization. JsonSerializerI nternalWriter.S erializeValue(J sonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerCo ntract containerContra ct, JsonProperty containerProper ty)\r\n at ...
I just found a pair of blog posts addressing this issue: http://blogs.msdn.com/b/sqlexp ress/archive/20 11/12/09/using- localdb-with-fu ll-iis-part-1-u ser-profile.asp x http://blogs.ms dn.com/b/sqlexp ress/archive/20 11/12/09/using- localdb-with-fu ll-iis-part-2-i nstance-ownersh ip.aspx
However, it seems easier to just use a local SQL Server instance if you are using full IIS.
I get the message "An issue in the ContactManager.WindowsStore.ex e process caused it to fail to activate. The process exited with a native exception. I've enabled the Nuget so it does compile just fine.