I have an endpoint that connects to SQL and returns a result set to the client. The WCF Service sets the MaxReceivedMessageSize to a low value and therefore the endpoint does not return a result set.
I fixed the issue by increasing the MaxReceivedMessageSize value. However, I need to see just how much data is coming from the endpoint to the client.
I tried using Postman but that's not working. What's the best way to capture what the endpoint is returning to the client?
Thank you
You can inspect or modify the incoming or outgoing messages across a WCF client by implementing a System.ServiceModel.Dispatcher.IClientMessageInspector and inserting it into the client runtime.
Inspect messages not only implements the inspector on the client side, but also manipulates the endpoint behavior.
Related
My WPF application is calling the WCF service using a single client object. This is working fine when request is sent and response is coming immediately before next request.
When I am sending the first request and it is taking 3 minutes to complete the calculation task and return the result. In the meanwhile second request is sent from my WPF application (ping request is sent every 3 second). At this time, I am getting the following error and WPF application getting disconnected:
The server did not provide a meaningful reply: this might be caused by a contract mismatch, a prematured session shutdown or an internal server error
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
My service behavior is written as follows:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults=true)]
I tried different combination and it is not working.
If you do multiple concurrent calls from singel client you should set ConcurrencyMode to Multiple in addition to InstanceContextMode ..
Note that if you set InstanceContextMode to Single, your service act as singleton, Then you should be aware of manipulating variables because it has reflection on other calls ..
Your Ping request should not use the same Channel. It should open it's own channel. Ideally, every independent request should open it's own channel (alternatively, you could build a queuing system). But accessing the same channel from two different threads is not going to work.
Im getting confused with WCF, can someone clarify this for me please.
According to Michele Leroux's WCF book the following is true.
"Regardless of the message-encoding format, messages are represented on the wire either as SOAP 1.1 or SOAP 1.2" - I confirmed this by creating a simple net.tcp bound service and used the WCF test client to see the request and response XML.
According to http://www.codemeit.com/wcf/wcf-restful-pox-json-and-soap-coexist.html however, the following is true."webHttpBinding specifies that the service understands generic HTTP requests instead of SOAP requests. The REST service is built on top of generic HTTP request with GET HTTP verb."
So how can both these statements be true?
WCF now has a split personality. The vast majority of it talks SOAP (1.1 or 1.2) and messages end up structured as SOAP on the wire even if the encoder produces something other than XML
However, the WebHttpBinding is special. It uses the Json/POX encoder which strips all of the SOAP framing off the message just sending the message body, however that happens to be structured, down the wire. This means that it can be used to send any content type over HTTP
Is there something in WCF that can simulate http streaming like IHttpHandler can do?
I want a way to constantly write bytes to my http response non stop to my client until there is nothing left to write using WCF and was just wondering if this is possible?
Thanks
WCF allows streaming by setting the TransferMode property of the binding to 'Streamed', 'StreamedRequest' or 'StreamedResponse', depending on your needs.
Check the following MSDN articles for more information on it:
Streaming Message Transfer
Large Data and Streaming
I'm contemplating a project where I'll be required to make use of what is variously called the "asynchronous" mode, or the "duplex" mode, or the "callback" mode of SOAP webservice. In this mode, the caller of the service provides in the SOAP header a "reply-to" address, and the service, instead of returning the output of the call in the HTTP response, creates a separate HTTP connection to this "reply-to" address and posts the response message to it. This is normally achieved in WCF using a CompositeDuplexBinding, like so:
<binding name="async_http_text">
<compositeDuplex clientBaseAddress="http://192.168.10.123:1234/async" />
<oneWay />
<textMessageEncoding messageVersion="Soap12WSAddressing10" />
<httpTransport useDefaultWebProxy="false" />
</binding>
This results in not one, but two HTTP connections per call: one from the client to the service, and then one from the service back to the client. From the point of view of the service implementation, nothing changes, you have a method that implements the interface method, and you take in the request and return the response. Fantastic, this is what I need, almost.
In my situation, the request and response can be separated by anything from minutes to days. I need a way to decouple the request and the response, and "store" the state (message, response URI, whatever) until I have enough information to respond at a later time (or even never, under certain circumstances).
I'm not terribly excited about having my methods essentially "paused" for up to days at a time, along with the required silly timeout values (if they're even accepted as valid), but I don't know how to go about putting a system like this together.
In order to be completely clear, I'm implementing a set of standards provided by a standards body, so I do not have flexibility to change SOAP message semantics or alter protocol implementations. This sort of interaction is exactly what was intended when the ReplyTo header was implemented in WS-Addressing.
How would you do it? Perhaps Workflow Foundation enables this sort of thing?
In such case don't use HTTP duplex communication as defined in WCF. It will simply not work because it is dependent on some other prerequisities - session, service instance living on the server, etc. It all adds a lot of problems with timeouts.
What you need is bi-directional communication based on fact that service exposes one way service and client exposes one way service as well (services can be two-way to support some kind of delivery notification). You will pass client's address in the first request as well as some correlation Id to differ multiple requests passed from the same client. You will call client service when the request is completed. Yes, you will have to manage all the stuff by yourselves.
If you are in intranet environment and your clients will be Windows based you can even think about changing your transport protocol to MSMQ because it has built-in support for all these requirements.
Edit:
I checked your updated question and you would call your communication pattern as Soap Messaging. I have never did it with WCF but it should be possible. You need to expose service on both sides of the communication - you can build your service to exactly follow needed contracts. When your service receives call you can use OperationContext.Current.IncommingMessageHeaders to access WS-Addressing information. You can store this information and use them later if you need them. The problem is that these information will not contain what you need. You have to fill them first on the client. This is generally possible by using OperationContextScope and filling OperationContext.Current.OutgoingMessageHeaders. What I'm affraid is that WCF can be "to clever" and override your changes to outgoing WS-Addressing information. I will probably try it myself during weekend.
It turns out the Windows Workflow Foundation (v4) does indeed facilitate this sort of message exchange.
Because WF allows you to decouple the request and response, and do basically whatever you want in the middle, including persist the workflow, idle it, and go outside and cut the grass, you get this capability "for free". Information can be found at these URLs:
Durable Duplex (MSDN)
Workflow 4 Services and duplex communications
With traditional ASMX web services synchronous request, the client connects, makes a request and waits for the entire message body to be returned.
I was wondering if its possible to have chunks of data flushed back to the client instead with WCF?
This way I can display some progress to the client app during the operation.
With WCF you can use streaming for download/upload. Check this links:
WCF Streaming in MSDN
File Transfer Progress example in CodeProject
Using WCF you can either use streaming or duplex messages to achieve that. Using streaming you are restricted to returning a single stream object. using duplex duplex messaging you pass a callback channel to the server and it can use that channel to make as many calls as you like to the client.