I have set up a WCF service. I have programmed the URL to be in the format:
http://localhost:64136/NewsProvider.svc/Rest/Getnews/1
When I set the return type to be XML I can change the number at the end of that link and browse the xml in a browser. However when I change it to JSON as soon as I hit the page in firefox I am asked do I want to download it?
How do I get round this and just view the pure JSON. When I used to write a page that wrote JSON I would add the following:
Response.Clear();
Response.ContentType = "text/plain";
Response.Write(json);
Response.End();
But I dont see how to change the content type and mess with the response object with WCF?
And will changing the content type actually let me just view the raw xml in the browser what govers this?
Yes firefox will offer you to open or download the content and if you do it you will see the passed JSON. If you don't like it you should install some Firefox extension (like JSONView) or HTTP proxy (like Fiddler).
Related
When I test operations in my web service (the "invoke" button), the XML result is not shown, but it is like a string. When I call it from Google Chrome, it gives me XML result...
Firefox was showing XML and it just stopped, but only when I test operations. The Service Description (the link on the main .asmx page) is showing a XML file of all operations on the web service and the result is in XML...
What seems to be the problem ?
Thanks.
For me it was Avira Browser Safety addon.
Once removed from installed Firefox addons, XML display worked like a charm.
Anyway, try starting Firefox in safe mode and check if XML result is ok.
If so, try disabling each addon in turn, until you find the wrong one.
My guess would be that the HTTP header of the service description have a Content-Type : application/xml but not the call to your web service.
One way to check that would be to use fiddler and try to add a Content-type field to the header of your call. (You can use a breakpoint to make it easier) Then you can see the real result.
I am making a web site in asp.net with c sharp.
I need to place a download file functionality(pdf, doc, xls) on one of my web page.
How can I do that?
If you want to do this automatically when a link is clicked from the server side, you have to send the file back yourself rather and add a couple of custom headers to the output. The way to do this is to use Response.TransmitFile() to explicitly send the file from your ASP.NET application and then add the Content Type and Content-Disposition headers.
For example:
Response.ContentType = "application/ms-excel";
Response.AppendHeader("Content-Disposition","attachment; filename=someFIle.xls");
Response.TransmitFile( Server.MapPath("~/somewhere/someFIle.xls") );
Response.End();
This will cause a Open / Save As dialog box to pop up with the filename of someFIle.xls as the default filename preset.
To force downloads, you have to set a couple of http headers. Content-Type and Content-Disposition. The first has to be application/octet-stream, and the second has to look something like this:
Content-Disposition: Attachment; Filename="[path to file user wants to download]"
I'm using a WebBrowser control in Silverlight and I'm setting it to a local HTML page. The HTML page has various links and they all work fine. Can I make it so that if the user clicks on an image file, it downloads to their system (or does the default behavior of the broweser) instead of displaying on the webpage? The main question is, is it possible to do this if I don't have access to the server itself? Thanks
edit - Is it possible to send an HTTPWebRequest to get the image and then edit the response headers, all from the client? This may be an alternative.
The standard way of doing this is to send the Content-Disposition HTTP header with attachment as the value. See here for more on this: Uses of content-disposition in an HTTP response header
But if you don't have access to the server, I don't think you can achieve this.
I am developing the REST enabled WCF Service. I am using the following code inside the interface.
[OperationContract]
//[WebGet]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
List<String> GetProjects();
I want the method should return the JSON response. I am passing the parameter through the URL as follows.
http://localhost:51565/RestWebService/Search.svc/GetProjects
Now when I use the above URL in the address bar, the browser ask me for downloading the file. I am new the REST web service & also JSON. I am not aware whether in the above case I am getting the JSON response or something else ? How can I identify that the above response is the JSON response ?
Most of the the current browsers do not render Json when they see the media-type application/json. You will run into this problem with many media types. My suggestion is to just stop trying to debug using a web browser.
Install fiddler. It will save you.
Fiddler is a debugging tool for working with HTTP. You will be able to see exactly what is being transmitted to and from your service and you will be able to create POST requests in order to test your service.
It does take a bit of time to get used to but it is well worth it if you are doing any amount of work with HTTP.
Download file and look inside if you have a valid json object. Eventually parse using jQuery.parseJSON.
Browser propmts you to download because it received a content type is does not understand, does not have too much to do with content. It is not the responsability of the browser to decide if its a valid json but of the calling code.
I second fiddler for its JSON support, but for instances where you can call the service with a GET request then Chrome will display the result in the browser just fine.
Just copied this out a Chrome tab after calling a WCF service
{"GetDetailResult":{"Address":null,"MainPhotoURL":null,"Photos":[]}}
I am working on a Custom WebPart, for which I need an application page to render a PDF file.
I am currently using following link http://support.microsoft.com/kb/306654
It works fine in ASP.NET, but gives a blank page in SharePoint.
Here's the code:
(PDF file is in same directory)
Response.ClearContent();
Response.ClearHeaders();
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath("Test.pdf");
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.Flush();
Response.End();
Working on it for last few hrs, making me crazy...any ideas?
A few ideas:
If the file is in the SharePoint directories, why not just redirect to a URL for it?
If you use Fiddler (or Firebug) to look at the HTTP traffic -- do you see the content-type change? What is the content (is it a PDF?)
The main differences between SharePoint and ASP.NET (assuming that you are getting to the file correctly) is that the page life-cycle is slightly different and the security model. You might want to look at how Reponse.End() works to make sure it isn't different in SharePoint. You can run SharePoint in verbose logging and then use .NET Reflector on the SharePoint dlls (with the logs as a guide) to see if there's some weird way of handling this. The SharePoint dlls have pretty liberal log calls. More info here: http://www.andrewconnell.com/blog/archive/2008/06/11/SharePoint-Debugging-and-Logging-Tips-and-Tricks.aspx
Have you considered rasterizing the PDF and just showing it inline in the page? This is what we do in a project my company is working on to view PDF and other documents in SharePoint (Vizit). You still have to solve your problem of reading the file, but instead of responding with the PDF, you respond with a PNG and request inside of an <img> tag.