Azure WCF service can't connect to SQL Azure - c#

I'm new to Azure and I'm doing a small test:
I have a SQL Azure database and I use EF6.
I also have a cloud service which connects to the Azure database (a "Windows Azure Cloud Service" with 1 web role).
My service has 2 methods:
GetString(): returns a string.
GetUsers(): return users from table [User] in my Azure database (returns IEnumerable<User>)
When I call GetString() it works fine.
when I call GetUsers() I get the following error:
The underlying connection was closed: The connection was closed unexpectedly.
I've also tried using the WCF Test Client and get the same error.
When I create a console app which connects to my SQL Azure (with the same connection string), everything works fine and I get a list of my users from the database.
The problem only happens when connecting to the database from within the Azure service.
My SQL Azure is configured to allow WINDOWS AZURE SERVICES.
Any ideas?
Thanks!
** UPDATE **
When I use the service locally I get the following error while calling GetUsers:
An error occurred while receiving the HTTP response to localhost:50119/MyService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

I figured this out:
Behaviors, Bindings and Services was not configured in my web.config file. I thoughts it should be configured by default and probably i was mistaken.
Thanks!

Related

How do I know what might caused a connection to a ASP.NET WebApi service to be forcibly dropped?

I am making a Winforms app that must connect to a ASP.NET WebApi web service that I also made. When I connect to the web service from my computer the Winforms app works, but when I install the Winforms app on some computers it fails to connect to the web service with the following exception:
System.IO.IOException: Can not write data to the transport connection:
The interruption of an existing connection has been forced by the
remote host
The problem is that this error might be due to a connection error or due to bugs in either the Winforms app or the web service and I have no idea what might be the cause. I can connect to the server where the web service is hosted. Are there any server logs that I can use to see what might be the cause of this error and if there are, where do I check them?

From WCF to API call - No connection could be made because the target machine actively refused it

I am calling a external API from a WCF service and getting below error.
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it xx.xx.xxx.1:443
If am making same API from console application then it is working fine.
How can I make same API request working from locally hosted WCF service?
When you run the console app you are communicating with the API under a different account to the one that's used when the WCF service hosted in IIS is communicating to the API.
When it's hosted in IIS, it will be using whatever is set in the Identity section of Advanced settings for the application pool. This will usually be something like 'ApplicationPoolIdentity' or 'NetworkService' etc. It may be that this account used for the Identity is unable to communicate to the API.
One test you can do to rule out issues with the account used for the Identity is to use your domain account for the Identity and see if the communication succeeds (i.e. try impersonation).

WCF Service not connecting to MSSQL

I made a xamarin android app that is supposed to connect to a database. I created a WCF Service that is hosted at a specified address. I then used SLsvcUtil.exe to create a proxy client to call various methods in my service. Previously I had zero issues connecting to the database but after updating my service, it can't even connect to the database. I receive the following error:
System.Reflection.TargetInvocationException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
The machine that is hosting the database has firewall turned off. The WCF Service is hosted on a seperate machine. I checked to see if mssql is accepting remote connections and it is. I have TCP/IP protocols enabled. I don't know if it will help but I am using LINQ to connect to the database and using visual studio. I can see that with using LINQ to SQL, a connection is seen on my machine (which is hosting the database).
Anyone have an idea?
i did some tests about connecting android apps to wcf, and all my tests fails, i recommended to you to change the approach, use REST api or web API to communicate android device to .NET backend.

Unable to connect with Azure SQL from Azure VM using Site-Site Connectivity

We have created simple classic Azure VM and have Azure SQL.
We have an application running on VM and trying to do some operation on Azure SQL, however we are not able to access it and got generic exception
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections
We already did list of things:
Added VM's public IP in remote database server
Added Endpoints for 1433 TCP thru Azure Dashboard
Added Inbound rule for 1433 in VM' Firewall
EDIT
For site-to-site VPN,
we linked our database to cloud service of VM
traced IP of database, now we are able to telnet IP with 1433 within
VM.
But still we are logging below error on logger when trying to interact with database.
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.
Are we missing something here
Generally connecting from Azure VM to Azure SQL is a bit different then connecting from outside of Azure.
assuming you are using the latest V12 Azure SQL and latest .Net framework or SSMS
you need to open on your VM outbound connection with TCP port range 11000-11999 and 14000-14999
make sure you do not have any blocker (firewall, 3rd party application that uses this port ranges)
from the Azure SQL end you can just click on "Allow Azure Services" on the Firewall configuration blade to allow connection from within Azure
you can read more about ports used when connecting to Azure SQL here: https://azure.microsoft.com/en-in/documentation/articles/sql-database-develop-direct-route-ports-adonet-v12/
and regards the Firewall configuration on Azure SQL you can read more here: https://azure.microsoft.com/en-in/documentation/articles/sql-database-firewall-configure/#connecting-from-azure
Facepalm moment for us.
Our internet wasn't working that is why we weren't able to connect to our database. As per web we did add MSFT's public DNS Servers i.e. 168.63.129.16 and 168.62.167.9. for classic VM's configure tab.

ASP.NET website consuming WCF service error

I get the following error on my asp.net website, while trying to invoke a wcf service method:
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 77.XXX.XX.XX:809
And then more in detail, I get a socketexception, webexception and also this endpointnotfoundexception:
There was no endpoint listening at
http://77.XXX.XX.XX:809/RemoteSyncService/ that could accept the
message. This is often caused by an incorrect address or SOAP action.
The wcf service (RemoteSyncService) is hosted in a .net application on the 77.XXX.XX.XX server. The binding used is basicHttpBinding.
The endpoint address, used in the asp.net site web.config is:
http://77.XXX.XX.XXX:809/RemoteSyncService
// this is the same on the remote server
The service code for the asp.net website was automatically generated, by using the 'add service reference' feature in VS2010 (on this address: http://77.XXX.XX.XXX:809/RemoteSyncService/mexHttp, as described in the other remote server).
All works perfectly on the dev machine..
What I tried and works:
running/debugging the asp.net locally, and invoking methods
trying to contact the wcf service with wcf test client
the asp.net site can contact the other server, because a ftp transfer from my asp.net site to the remote server was successful
pinging the remote server
Will provide code if needed..
make sure your production server isn't firewalling you.

Categories