Method not allowed in REST PUT - rest

I know this has already been asked. I am in a crisis here.
I cannot make a PUT method to work. Just REST services. iis 7 windows 7 64 bits.
I get Method not allowed, and not a single hint. I am using a .svc file.
Please help!
Thanks

There could be many reasons why this is happening, I would recommend that you add the below to your web.config (just before the is closed), so that you can get some diagnostics information on what your WCF webservice is doing :
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\webservicelog.svclog" />
</listeners>
</source>
</sources>
Also, are you placing PUT in the method operation contract like below :
[OperationContract]
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "DoWork")]

I have been downvoted, but if you check around, many people has been troubled by this.
So, things I learned:
ENABLE Trace Failed Requests!!! I was relunctant, and I should have done it before. Might have saved a full day and night, because I am the kind of guy that get obsessive with technical problems.
PUT methods can not be tested via url in a browser!!!!
I finally solved it by uninstalling WebDAV, thanks to Failed Trace!! I had already tried that, but I was sometimes checking with Chrome Rest Extension, and sometimes via URL in a Browser. Apparently, when I firt tried WebDAV uninstall, I never checked with Chrome Rest...
I know, I know, a was until yerterday a complete newbie. Now I am just a newbie.
I ended up writing my own code to consume the services to have full control.
For you guys having the same problem, please enable tracing failed request. Then, in the XML output, look for:
405
Close to that you will found the bastard causing it. In my case, it was webDAV.
Rememeber to use a tool that actually sends a real PUT verb, like rest Chrome Extension, or your own app. NOT URL in a Web Browser.
Regards

Related

How can I actually download/transfer a file found using UPnP?

I'm completely new to UPnP as a protocol, but I'm hoping to use it to transfer files from a Sony Camera to an iOS app I'm working on. So far I have SSDP discovery setup, I can read the UPnP client's services, search through folders and access file names, but the final hurdle which I'm stuck on is how to actually download/transfer the files once I'm able to list them!
What I end up getting is the below:
<item id="04_02_0624600856_000001_000001_000000" restricted="1" parentID="03_01_0624600856_000001_000000_000000">
<dc:title>DSC05076.ARW</dc:title>
<upnp:class>object.item.imageItem.photo</upnp:class>
<dc:date>2018-08-23T12:24:21</dc:date>
<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_SM;DLNA.ORG_CI=1">http://192.168.122.1:60151/SM_DSC05076.ARW?%2104%5f02%5f0624600856%5f000001%5f000001%5f000000%21http%2dget%3a%2a%3aimage%2fjpeg%3aDLNA%2eORG%5fPN%3dJPEG%5fSM%3bDLNA%2eORG%5fCI%3d1%21%21%21%21%21</res>
<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_LRG;DLNA.ORG_CI=1">http://192.168.122.1:60151/LRG_DSC05076.ARW?%2104%5f02%5f0624600856%5f000001%5f000001%5f000000%21http%2dget%3a%2a%3aimage%2fjpeg%3aDLNA%2eORG%5fPN%3dJPEG%5fLRG%3bDLNA%2eORG%5fCI%3d1%21%21%21%21%21</res>
<res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_CI=1">http://192.168.122.1:60151/TN_DSC05076.ARW?%2104%5f02%5f0624600856%5f000001%5f000001%5f000000%21http%2dget%3a%2a%3aimage%2fjpeg%3aDLNA%2eORG%5fPN%3dJPEG%5fTN%3bDLNA%2eORG%5fCI%3d1%21%21%21%21%21</res>
I would (With my naive experience of simple HTTP APIs) then expect to simply be able to download the file in question by hitting:
http://192.168.122.1:60151/SM_DSC05076.ARW or similar (I'm assuming I have to change this URL slightly as the file is listed as image/jpeg rather than RAW?
Whatever combination I try of the full res object, snipping bits, decoding the url e.t.c. I always get a 404 response when trying to visit the URL in question. Is there something more complex I need to do here? Or something simple that I'm missing?
Thanks in advance!
The problem here was that I was using a url from a previous session. It turns out that the urls change between connection sessions, which is why I was getting a 404.
Lesson learned: UPnP is highly dynamic, and you can’t rely on caching images under their access MRL!

IIS 10 giving 401.3 access denied for PUT, DELETE, or PATCH for specific path

I'm working on a REST API, and doing test and prototype work on Windows 10 with its native IIS install. The API is written in C#. I've created a class that derives from IHttpHandler, and derive from that to implement classes for my API's nouns. (This allows me to commonalize logging, config, auditing, etc, in my base noun class). To implement verbs, the derived classes override the base class' functions for GET, POST, etc.
Anyway, one of the nouns I have is for access to the application's log. The path for this is /log. In it I've implemented GET, to read the log, and DELETE, to clear the log. GET works fine, however, DELETE gives me a 401.3 from IIS. I also get the same 401.3 if I try PUT or PATCH. PUT and PATCH are not implemented in the Logging class, so they should return a not implemented message. I do get the not implemented message if I try POST (which is not implemented in exactly the same way that PUT and PATCH are not implemented).
As part of trying to narrow down this behavior, I checked whether there were specific verbs being blocked by request filtering (there weren't). I checked whether Process Monitor was catching file system access denials at the underlying path (it wasn't... things never got that far.) I then tried adding another handler mapping - exactly the same as the first, but with a different path name:
<handlers>
<add name="BLOBRepoLog" path="log" verb="*" type="BLOBRepoService.Log" resourceType="Unspecified" preCondition="integratedMode" >
<add name="BLOBRepoLogSanityCheck" path="foo" verb="*" type="BLOBRepoService.Log" resourceType="Unspecified" preCondition="integratedMode" >
</handlers>
Using Postman, if I call DELETE on /log, I get the 401.3. If I call DELETE on /foo, it works correctly. If I call PUT on /log I get the 401.3. If I call PUT on /foo, I get the correct not implemented message.
Anyone have an idea why IIS should be doing extra scrutiny on verbs called for the /log path?
Thanks,
Paul
I had a similar issue where Put and Delete weren't working, it turned out for me that Webdav was the issue. In my case I didn't really need it so I uninstalled it and everything worked.

Post csv content to Web Api

I have a c# console application which post .csv content to a web service. If I run my solution through VS, it runs perfectly fine but after deploying web service on IIS I keep getting Multiple Choice Status Code 300 error. Not sure how to resolve that. Any pointers would be appreciated.
Thanks
These are relatively simple but I cannot think of other possibilities based on your description.
One of my recent designs had a literal in the code that when I deployed it ended up using a different port which I had forgotten to change to a relative reference.
If not that then the other problem I had with it was because I used JSON to link to the web service. While it worked when viewing in VS when deployed my JSON reference was actually incorrect. specifically it had to do with code in my web.config file, which would be the app.config file for your console application. I had used the code
standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="false" crossDomainScriptAccessEnabled="true"
when I should have also added
defaultOutgoingResponseFormat="Json"
to make the code work

Apps>Menu>Basic 405 Method Not Allowed

I am hosting my pages on my doamain. I put the following info. When I go to view the app it shows 405 Method Not Allowed..Not sure what I am doing wrong.
*
The first page load a APP makes is a POST request.
Seems your server could be rejecting them.
Its worth checking the server side error log for further information.
Indeed, it will most probably be a setting on your server. I had the same problem, my server didn't allow POST method on .html pages, changed my canvas page source to .php and all works fine now.
If you can look at your apache logs, it will provide a more clear error that we can help you debug with. Though a 405 error typically signifies a problem with the server and usually stems for a POST request.
I have made the mistake 2 times of creating my site in html instead of using a scripting extension. For example, if you are running on a Windows server and coding in Visual Studio, it is tempting to just create .htm or .html files. However, most web servers will not allow a POST operation to these pages. Instead, create .aspx pages, which will still allow you to use the same exact static HTML and JavaScript. This solved my problem in both cases.

ASP.NET MVC users not being copied over on publish

I'm new to ASP.NET MVC, and I'm trying to convert a very simple ASP.NET application to MVC with authorization.
I have it working locally just fine, but when I publish to IIS, the users database is apparently not copied over correctly (even though it is running on the same machine that I am developing it on)
It does not appear to be a database access issue, since when I create a new user using the Register link I can log in just fine. The problem is, all the users (and their associated roles) I created using the ASP.NET Web Site Administration Tool aren't being recognized. The error message it gives me is a simple "log in or password is incorrect" - there's nothing about not being able to access the database or anything like that.
Does anyone know where I should look for the source of this problem, or has anyone else had this problem before?
Potentially releveant additional information:
When I first published the project, I got an error in my web.config that said "ApplicationServices" was already defined, preventing me from accessing any page on the site. I "fixed" this in a manner that would be called "hacky" only if someone was trying to be polite - I added "<remove name="ApplicationServices" />" right above it, so that portion of the web.config looks like this:
<remove name="ApplicationServices" />
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
Any ideas?
Roles and Users are partitioned by ApplicationName. Check the aspnet_Applications table and compare that to what you see in aspnet_Roles and aspnet_Users.
This post by Scott Guthrie explains what is probably happening, and how to configure the ApplicationName on your providers.