I am getting 'connection refused' or 'bad request' when trying to connect from the android emulator to my web service on localhost. I have added the port number to the firewall to allow connections, and I have tried the advice given here to modify applicationhost.config
Both the web service and the emulator are running on the same (Windows 10) PC. In the server's web.config I have the following under 'system.webserver':
<httpProtocol>
<customHeaders>
<clear />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST" />
</customHeaders>
</httpProtocol>
AFAIK the emulator can find the web server (I'm not getting a 'not found' error), but the server refuses a connection.
using (WebClient client = new WebClient())
{
string json = ......;
client.Headers[HttpRequestHeader.ContentType] = "application/json";
// I have also tried "application/x-www-form-urlencoded";
string result = client.UploadString(UrlBase.urlBase + "SaveLocation", json);
If 'UrlBase' is http://192.168.1.73:60080/Service1.svc/, I get 'Bad request', which I know can result from badly formatted json.
If 'UrlBase' is a remote server, the connection works (so I know the json format is correct). Same updated dll running on both remote and local server.
If 'UrlBase' is http://localhost:60080/Service1.svc/, I get exception 'connection refused'