Send message to sender of SignalR request - c#

Can you with SignalR send information the client who has send the request? Here I've quickly draw the current situation with paint:
The client send a SignalR request to the server with
meldingenHub.server.vote();
and the server send a message back to all the clients with
Clients.All.SendOke();
The situation I will have is that only the sender of that request, receive the message I send form the server. All the other clients don't receive that message. Is there something I can use like this:
Clients.Sender.SendOke();

When the Server method is invoked, there is a Context object populated with the details of who called the method. There is a property in here called ConnectionId which has the identifier of the caller.
So to invoke a method only on the sender's client, simply call:
await Clients.Client(Context.ConnectionId).SendAsync("ClientMetodName");

What you need to do is send the connection id of the sender to the hub and then use Clients.Client(connId).broadcastMessage(....) see THIS other answer for an example.

Related

Retrieving an inbound message using the Mandrill API

I'm trying to retrieve inbound messages from the API on Mandrill, but when I call the sendRaw method, the API fails with an error saying I need to specify a raw message value. I guess the SendRaw is sending the message I specify, rather than returning the message I request?
static async Task<string> SendRaw(string key)//,string )
{
string sendRaw = mandrillAPI + "inbound/send-raw.json";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(sendRaw);
HttpResponseMessage response = await client.GetAsync(key);
string s = await response.Content.ReadAsStringAsync();
return s;
}
The raw message is the content I'm trying to retrieve, so I don't see how I can supply it.
Is there a way to retrieve messages from the server using the API? And if that is the wrong way to say it...lets put it this way: I set up a domain with Mandrill and sent a message to a fictional mailbox on that domain. The server relayed the message--I can go on the Mandrill dashboard and see the SendRaw API call for the message. I would like to retrieve the message from where-ever it is located...whether it is located on Mandrill's servers or whether it was sent to my domain where I needed to have something listening for the send, I don't know. I'm very new at this (circa yesterday). Either way, I need to get that message. Is it possible to do it using the API?
Or is Mandrill just relaying the message to my url when it is originally sent, and I need to set up the url to receive the message in order to get it?
Inbound mail can't be retrieved through the Mandrill API. Inbound mail is received by Mandrill, converted to an inbound/send-raw API call, and then POSTed to the webhook that you've specified for your inbound route. Mandrill doesn't store the message contents for API retrieval. Once they're POSTed to your webhook URL, the message is discarded. Note that inbound/send-raw is different than messages/send-raw. The inbound/send-raw API call allows you to mimic what would happen if you sent a message to a route that you've set up (ie, POSTing to the webhook URL).
More information about how inbound mail works and the webhooks can be found in the Mandrill KB: https://mandrill.zendesk.com/hc/en-us/categories/200277247-Inbound-Email-Processing

Twilio Click To Call 'no-answer' status in JavaScript client

Is there any way to know if an outgoing call was not answered using only the Twilio Click To Call JavaScript client?
Twilio.Device.disconnect(function (conn) {
logAndDisplay('Call ended');
});
Checking conn.status() after a call was not answered is 'closed' (same as if a call was answered) so there is no way to figure out the difference.
Before the JavaScript disconnect callback is called the no-answer status can be retrieved on the server from DialCallStatus. In case that status is not available on the client, is there a way to send the server value and access it on the client?
In the end I could not find how to read a no-answer status on the client.
The (hacky) solution was to make an AJAX request to the server to get that status.

Reroute incoming request

How can I send a received request to another url, and send the response to the original sender?
I have an ashx generic handler and can get the sent request using Request.InputStream . However - that doesn't include everything (like headers). Is there a way of sending the whole request as is, and then sending the whole response as is?
Just to be completely clear: a.ashx gets an HttpContext from somewhere.com. I want it to send the response as if somewhere.com was communicating directly with b.ashx.
Have you considered using the Server.Transfer to redirect the query to the required url?
Simply use
Server.Transfer("Page2.aspx", true);

Get SOAP request body in proxy client

I have application which calls a WCF service. For monitoring and tracking purposes I would like to have log all request messages for which application failed to call a service. Loke I need to call operation called RemoveSubscription and once failed(may be network problem or WCF service was down) I would like to log the SOAP message into xml or txt file.
Generaly is it possible to get the request SOAP contact in proxy class.
I found some info that it can be done by extending SoapExtension class. If this is the right way how to register/inject the new class which extends SoapExtension to channel stack.
EDIT : Service is not hosted in IIS it is in Windows service... so I am i right that in this case SoapExtension is not the right solution.
With a WCF based client, you can create an endpoint behavior to intercept the request & response messages. This TechNet article shows how to access the message being sent and the response message. Your WCF client can be generated by either adding a Service Reference in Visual Studio, using SvcUtil to manually generate your client code or rolling your own proxy directly in code using the ChannelFactory class.
Your logging code would always write out the request message with a status of requested and a timestamp to some data store (file, database, etc.) When the response message is received, it would match request message somehow from the response message contents and update the data store to change the status to responded. Selecting all the messages from the data store with the status of requested older that some time period would list all the failed messages.

HttpWebResponse.GetResponseStream(): when is the response body transmitted?

I'm using the System.Net.HttpWebRequest class to implement a simple HTTP downloader that can be paused, canceled and even resumed after it was canceled (with the HTTP Range request header).
It's clear that HttpWebRequest.GetResponse() is when the HTTP request is actually sent to the server, and the method returns when a HTTP response is received (or a timeout occurs). However, the response body is represented with a Stream, which leaves me wonder whether the response body is actually transmitted with the response header (i.e. it's already downloaded when GetResponse() returns), or is it only downloaded on-demand, when I try to read from the response stream? Or maybe when I call the HttpWebResponse.GetResponseStream() method?
Unfortunately the msdn documentation doesn't tell, and I don't know enough about the HTTP protocol to be able to tell.
How do chunked transfers and the like behave in this case (that is, how should I handle them in my C# application)? When is actually the response data downloaded from the server?
This all depends on TCP, the underlying protocol of HTTP. The way TCP works is that data is sent in segments. Whenever a client sends a segment to the server, among the data sent is information about how much additional data is it ready to receive. This usually corresponds to some kind of buffer on the client's part. When the client receives some data, it also sends a segment to the server, acknowledging the received data.
So, assuming the client is very slow in processing the received data, the sequence of events could go like this:
Connection is established, the clients says how much data is it ready to receive.
Server sends one or more segments to the client, the total data in them at most the amount client said it is ready to receive
Client says to the server: I received the data you sent me, but don't send me anymore for now.
Client processes some of the data.
Client says to the server: You can send me x more bytes of data
What does this mean with regards to GetResponse()? When you call GetResponse(), the client sends the request, reads the HTTP header of the response (which usually fits into one segment, but it may be more) and returns. At this point, if you don't start reading the response stream (that you get by calling GetResponseStream()), some data from the server is received, but only to fill the buffer. When that is full, no more data is transmitted until you start reading the response stream.

Categories