WCF streaming on asmx? - c#

I've got wcf service for wcf straming. I works.
But I must integrate it with our webserice.
is there any way, to have webmethod like this:
[webmethod]
public Stream GetStream(string path)
{
return Iservice.GetStream(path);
}
I service is a class which I copy from WCF service to my asmx.
And is there any way to integrate App.config from wcf with web.config ?

Sorry, no, ASMX web services don't support streaming.

What is the bigger picture here, what are you trying to archieve with this stream?
Like John Saunders already said: Webservices dont support it. This is behaviour by design: Data is serialized into a platform/language independent and human readable xml packet, sent and deserialized on the receiver side. Of course you could go and split up your stream into chunks and send it piece for piece. But it wouldnt really make sense to misuse webservices like that, plus you are adding huge overhead in bandwidth and processing time.

Related

Which is the best way (WCF or WEB API) to send data(complex data/primitive data) to a service and get the response(complex data/primitive data)

I have one scenario, Let Say A is a Web based Application and needs to show some data on screen based on data returned from component B.
Now A send some data(which is going to be input parameter for a component B) on an event to B , and component B is going to do calculation on input parameter and return data to A.
Both A and B are handled by different organization, So what is the best way to communicate between them, is WCF or WEB API(also suggest how can we implement this scenario)?
I am thinking of creating Web API for component B here , so that A can consume that and call component B,and Transfer data in JSON format.
But the issue in this approach is that, this request is going to be GET Request, and we can't send complex types on GET request. Even if we are communicating through JSON format, how can we send huge data in GET request.Please correct me if mine understanding is wrong.
No of Input Parameter is ranging between 10 to 20 and number of request made to Component B is very much frequent, So we have to take care of performance as well.
Updatde 1: First Issue is we can't send data in Request Body for GET.
Generally the question is WCF for complexity and security vs WebApi for simplicity and speed. If WCF features are not required, I will go for WebApi. If you need to send complex data with request, you can use POST.
It is perfectly correct to request data using POST, there are only small limitations.
Look here: https://www.w3schools.com/jquery/jquery_ajax_get_post.asp

Proprietary bare-bone ASP web service

I want to create a proprietary minimal / bare-bone / data-light webservice. I prefer not to use the standard solutions like Restful, WebAPI, SOAP, WCF, etc.
I just want a web server listener that can receive and process 1 UTF8 string (own message format) and respond with 1 UTF8 string as the result.
My question is: can you give me a starting point, by providing a code example of the interface. Of course not the complete implementation.
Data transfer has to be as minimal as possible (no avoidable headers).
NB: Server language has to be .NET. Code example may be in C# or VB.
The most bare-bone thing to create a web service would be an HTTP Handler.
The sample I linked returns HTML but you could send back XML as well (or anything else really, just make sure to return an appropriate Content Type).
The call to your method would be a regular HTTP call of the URL of your Handler.

How to get XML from webservice?

I am going to have XML output from web service. in fact, I write a method in web service that returns a first of objects, now I want to have this list of objects in XML format in client side.
Does web service produce XML output?
If yes, how can I get XML in client side?
I don't want to write XML document in web service
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
return
<string>Hello World</string>
Please help me
I'm not entirely sure your question makes sense:
does web service produce XML output?
It can pretty much return whatever you like. You can make it return raw xml, you can make it return XmlNode-objects, or something similar.
This is what confuses me:
I don't want to write XML document in web service
Does this mean you don't want to build the XML-object at all, on the server side? If so, it will be up to your client to create the xml. How you can do that obviously depends on what data you are returning. I don't think there is any "magic" in c# that will do this for you automatically, just because it is a response from a WS.
Regarding your specific issue, you can find some guidance here.
When defining the details of your data contract and your WCF endpoint, you can decide the exact communication protocol and the form used to return your results. There, you could set the options of using REST or SOAP (see this for more) or returning results as JSON or raw data.
Hope I helped!

WCF Http RouteTables (for versioning)

I currently have something like this for my route table. Is there a nicer way to handle versioning in WCF Web API or conventional WCF?
RouteTable.Routes.MapServiceRoute<Service1>("1.0/Route1", Config1);
RouteTable.Routes.MapServiceRoute<Service2>("1.0/Route2", Config2);
RouteTable.Routes.MapServiceRoute<Service3>("1.0/Route3", Config3);
RouteTable.Routes.MapServiceRoute<Service4>("1.0/Route4", Config4);
You could do that, but it is very protocol-bound, in this case HTTP. I wonder if there is a way to do that without worrying so much about protocols? Ideally we only want to do it once and not for each transport out there. Luckily there is a way, let me explain.
At the end of the day, your WCF internals should be protocol agnostic. By that I mean by the time a method is invoked on your service, we should not care whether it came by REST, TCP, HTTP or named pipes.
In WCF this is pretty easy and so is versioning. With versioning we can learn much about .NET interface versioning particularly when it has nothing to do with WCF. The idea is that your service should realize:
interface ISomething1 { ... }
Later when a new method or changes are required you should:
interface ISomething2 : ISomething1 { void SomethingNew (...) }
It's then a simple matter to publish your service with 2 endpoints in config, one pointing to ISomething1 and the other to ISomething2.

Raw SOAP data with WebServices in C#

Where can I find the RAW/object data of a SOAP request in C# when using WebServices.
Can't find it anywhere. Shouldent it be available in the HttpContext.Current.Request object ?
Shouldent it be available in the HttpContext.Current.Request object ?
No, it shouldn't.
What are you trying to accomplish? If you just want to see that data so you can log it, or as an aid to debugging, then see the example in the SoapExtension class. It's a working sample of an extension that can log input and output as XML. I've used a modified version of it myself.
If you're just looking to debug your web service, then you can install Fiddler, and that allows you to inspect the data sent to and from your web service.
It sounds like you're going to have to go lower level on your implementation if you want to see the raw XML. Check out the generic handler (ASHX extension). This will allow you to deal with the request/response streams directly. It's very low level, but gives you full control over the service lifecycle.
I found
Request.Params[null]
refers to the RAW data posted to the page in C# ASP.NET.

Categories

Resources