I am trying to figure out how to stream a file (typically a PDF) from a web service that is front ended by a typical web site. The PDFs do not physically exist, but are created on the fly by a report generator (think Crystal, Telerik Reporting, etc.)
I can do this today directly from the web site by doing a Response.Clear() followed by setting the ContentType and adding the appropriate Content-Disposition header finally followed up by a Response.BinaryWrite(...).
But, a WCF service (IIS hosted in this case), does not have a Response object. I have tried passing in the Response object from my web page as a parameter, but I can't even start the WCF Service because HttpResponse cannot be serialized.
Am I barking up the wrong tree? Is there a better way of looking at this? We wanted it in a common web service because more of our web sites are needing to do this and we don't want to maintain multiple copies of the code to do it.
You can send your file as byte[] array.
Or you can send this file as a Stream parameter (using Streamed mode)
Related
I created some chrome extension that detects a file download event and cancel the download, and gets the download link. Sends the link to myserver.
I want to create a server that recive link to download, download the file, do some manipulation on the file and sends the file back to client.
All the time I developed client side apps (Mainly with c#), and I don't know what to choose for the server side, WCF App or Web API (or something else). the server can be inside the organisation or remote.
What do you think should I pick? any suggestions?
It seems that creating Restful-style services may be more appropriate for this scenario.
You know, both WCF and Asp.net WebAPI can create Restful-style services. WCF could take advantage of the Webhttpbinding to create it.
As for handling file uploads and downloads, I don't think there is any difference between the two techniques. Perhaps the services created by Asp.net WebAPI are a little more mature, such as the ability to deal with form-data stream (multipart/form-data) directly. While WCF service could not directly process the form-data stream.
Here is an example of an upload and download in Asp.net WebAPI.
https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/sending-html-form-data-part-2
How to return a file (FileContentResult) in ASP.NET WebAPI
Feel free to let me know if there is anything I can help with.
Is there a way to use proxy concept with NancyFx? I mean, I would like to access a service and record the response in my Nancy application (as proxy), either on a JSON file (similiar to wiremock) or in memory (similar to mountebank)
Thanks in advance.
Have you considered WireMock.net as it has a proxy feature and saves the results to json files.
Towards the end of this article is an example of using the proxy feature of wiremock.
You could certainly write a load of code to log the request and response, and use one of the standard web clients to pass the request back to the service, but Nancy has no built in system for this - Nancy is an MVC web framework, not a proxy server.
Perhaps you need something more along the lines of Nginx?
I was recently assigned the task of creating a login page for my company and they're requiring that I use angularjs for the client side application.
The authenication services are asp.net web services that have already been coded, and return xml because of another service that also uses them.
I notice that AngularJS wants JSON data for it's return value.
I need a way of using AngularJS http methods get and post that will work with data from and to the web server using SOAP. My recent attempts have consisted of trying to get the xml back and then convert it to json on the client side.
Converting on client-side can potentially have problems and so I would prefer to keep all conversations on the server-side.
My solution would be something like have all my web services working as normal. Then have one web service that can take another method in as a parameter and call that method in code and return a json string.
Can anyone give me some input on this. My reason behind not wanting to simply change the web services to return json is because other applications use this service and are expecting xml, also there are more than 1000 web methods in place.
I may have found a solution I am going to work towards. However, if any viable options are still available that would simply add a new method to the list of web methods that would be great. Talking with the developer that wrote all the web services I will need to be using it would be simpler to convert the xml to json on client-side. I am also looking into some angular modules that people have written for get, post for soap services.
Found here
After lots of digging around the best option for me is to use this code Here. I can make the call easily and once I get the xml back just do angular.fromJson(angular.toJson(response)).
If ASP.NET WebAPI is used on the server side it may be sufficient to add an Accept header with the value application/json to the HTML request. It tells the server to return JSON instead of XML.
I am trying to upload a file from a client to a MVC application, and then have the MVC application pass the upload file to a web api.
So far I overrode the IHostBufferPolicySelector to stream any incoming HTTP requests that are greater than a given size. So any large file uploads made to MVC is being received as a stream.
I thought of two solutions to this problem, but open to any suggestions.
Have MVC temporarily store the file, then send that file over to the web api
Somehow pass the stream of the file that is coming into MVC, over to the web api
Is there a way to achieve option 2? Can I pass an incoming stream to another web service?
I recently got a requirement to develop a new web service, and I'm not entirely sure how to approach it.
I'm familiar with normal WCF web services, where the url is something like
http://server/site/Service.svc/SomeMethod
that you can post XML/JSON to.
The new service is supposed to accept an HTML file post, where the content type is
multipart/form-data
From what I understand, the form contains fields, one of which contains a bunch of XML data which I want to parse. I will then respond by posting my own similar html file to a remote location.
I'm not completely sure how to begin with this.
A WCF Service of some kind?
ASMX?
Or even an actual ASPX page that the client will post to?
You can use an .asmx file to create a web service and can use it through aspx pages