How to connect to remote gRPC service - c#

I created a gRPC service and client in C# .NET Core 3.1. When I deploy the service to localhost, I can connect to it without a problem. But when I publish the service to a IIS via WebDeploy and start it there I cannot connect to it.
For a local deployment, the channel is initialized as follows:
var channel = GrpcChannel.ForAddress("https://localhost:5001");
For the remote deployment I change it to the following value, since it starts as a HTTP service on http://localhost:5000 on the remote machine (which I also failed to find out how to change - I would prefer it to start as a HTTPS service):
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var channel = GrpcChannel.ForAddress("http://1.2.3.4:5000");
1.2.3.4 is the IP of the remote machine, which I am able to ping. I also created a firewall rule to allow all inbound traffic on inbound port 5000.
The client application fails on the first remote call with the error message
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I fail to understand which measures I have to take to create a connection to the remote service. All example gRPC code I have found so far uses localhost as a deploy point and did not help me figure out the root cause of my problem.
Any help or pointers towards what I must have missed are appreciated.

From Tutorial: Create a gRPC client and server in ASP.NET Core, a warning almost at the end of the article, says
ASP.NET Core gRPC is not currently supported on Azure App Service or IIS. The HTTP/2 implementation of Http.Sys does not support HTTP response trailing headers which gRPC relies on...
Please refer to gRPC in production for ways to run your gRPC service in production.

Related

I receive a CommunicationException on any port other than 443

I have a standard n-tier application (.Net 4.7.2) with a console server and a WinForms application both running on the same machine. The client and server communicate via WCF.
I get a CommunicationException on the client when I attempt to communicate with the server if I use any port other than 443 in my address binding. not specifying a port or explicitly specifying 443 works without an issue.
The error message is;
An error occurred while making the HTTP request to
https://localhost:44333/SecurityTokenService/issue/wstrust/mixed/anonymous.
This could be due to the fact that the server certificate is not
configured properly with HTTP.SYS in the HTTPS case. This could also
be caused by a mismatch of the security binding between the client and
the server.
here is my client binding for reference
<endpoint
address="https://localhost:44333/SecurityTokenService/issue/wstrust/mixed/anonymous"
binding="customBinding"
bindingConfiguration="MySecurityTokenEndpointBinding"
contract="System.ServiceModel.Security.IWSTrustChannelContract"
name="SecretTokenAuthenticationEndPoint" />
UPDATE: I have continued to investigate the issue myself and enabled WCF tracing. I can see from the trace logs the warning 'The Security Protocol cannot secure the outgoing message'
Make sure to use the correct way to call the wcf service, such as adding service reference, channel factory, etc. After reading your question, I think it is very likely as the error message says: 'This could also be caused by a mismatch of the security binding between the client and the server.'
You can use the following code to specify the TLS version:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
TLS1.3 is the latest TLS standard protocol, which is faster and has higher security.
Here is the reference: Transport Layer Security (TLS) best practices with the .NET Framework
The solution for me was to bind the SSL certificate to the IP Address and Port that my service was being exposed on. I used the following command from a command prompt;
netsh http add sslcert ipport={ipAddress}:{port} certhash={CertificateThumbprint} appid={appId}
Some points to note
If the above command fails; ensure you have the private key imported and not just the public certificate
I don't know if the appId is an arbitrary Guid; I used the Guid from my application shell project (a console application); It's the Guid that exposes your application to 'com'
Hopefully, this helps somebody in the future

No such host is known —> System.Net.Http.HttpRequestException:

I am developing bot solution, in which I am making REST call to get some details from other server.
In local host my code is working fine, but after publishing the code in Azure I am getting the below error:
System.Net.WebException: No such host is known No such host is known —> System.Net.Http.HttpRequestException: No such host is known —> System.Net.Sockets.SocketException: No such host is known
I am using HttpWebRequest option.
May I know what could be the reason?
I'm not sure the solution below will work for you but it looks like the solution is worth to be checked out. Here is an answer that may have useful information. Take a look at this answer and check your solution accordingly:
The problem description:
I deployed a .NET Windows Service on Azure Virtual Machine running
Windows Server with an opened port that allow me to connect to it,
this service is like a server using socket. The problem is that when I
try to connect from my PC to that hosted server it doesn't work and I
get this exception: System.Net.Sockets.SocketException: 'No such host
is known'. The port is opened and visible from my PC. Can someone tell
me why I get that exception? If I run locally all works ok.
The answer:
The Exception seems to be a DNS issue. I am not familiar with C#, from
networking, you could check the followings on your side:
Windows service is running and the port is listening on the Azure VM.
The port is allowed for outbound traffic from your PC and Inbound
traffic on your Azure VM. Check the VM firewall settings on both sides
between your PC and Azure VM. Also, you could check the NSG settings
follow this. You could use telnet vmpublicIP port on your PC CMD to
verify network connectivity.
Verify your PC can resolve the address of the hosted server if you connect
it via its DNS name. You could use the NSlookup or DIG to verify this.
If it's DNS issue, you also could add a line in hosts file (located in
%WINDIR%\system32\drivers\etc on windows) mapping the hosted server's
IP to a name. Hope this helps.
.NET Service System.Net.Sockets.SocketException: 'No such host is known'

.Net WCF Web Service Can't Connect from Client to Remote server

I have a client that connects to a WCF web server using NetTCPBinding. I have having issues connecting to the WCF remotely from certain machines.
I can run this client from my other computer to the remote web service however I have a new machine and I cannot connect to the WCF service while running the same client from this machine and I can't figure out why since I have not changed anything in the clients on both machines, they are exactly the same.
I get the error
"The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue."
So my question is,
Is there anything on a system level that could be blocking my client from making the connection to the service?
Thanks

Custom .net TCP server

Created .net custom tcp server and client using tcplistener. Taks is simple to exchange the data. I have Windows server, on which I am able to communicate. Within network also I am able to communicate. When I deploy this same on our web server, public IP is not accepting connections. At client side it throws time out error:
A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection
failed because connected host has failed to respond .....
Trace route shows request is going there till server and at the end its not showing time out. Server is VM on azure.
Add the endpoint to the Azure configuration:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-set-up-endpoints/
Thanks for your help. It was firewall issue. It is resolved but I am clueless about the problem. Firewall ports opened earlier did not worked. so I stopped firewall and I found its working. later on I started and firewall it again worked. strange....fire wall is not updated it seems.
Thanks.
Kishor

SignalR 2.2.0 WebSocket error connecting to hub

I have an ASP.Net MVC application that I have added SignalR to. After following the "Getting Started" tutorial (with modifications of course since it's going in my application) I got it working on localhost. However once it's in the production environment, I get the following error:
WebSocket connection to 'ws://xxxxx/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=xxxxx' failed: Connection closed before receiving a handshake response.
I can access /signalr/hubs (I get a js file). Any ideas as to why this would happen?
This may be due to the fact that your web server doesn't support WebSockets (IIS 7.5, for instance. It may also be due to the fact that you are using a "proxy" server like ARR and it just cannot "route" WebSocket requests.
The first thing I would try to do is to disable WebSockets on SignalR, just as a debug tool. Here's how: SignalR - How do I disable WebSockets
If your problem persists, it's a general SignalR problem but at least you will have a more specific error. If the problem stops, now you know it is a server issue.

Categories

Resources