I'm writing an application for Windows Phone 8.1. I have hosted a WCF service on IIS Express on my local machine and configured it to be accessible from the WP8 device that I'm using for testing (done all the endpoint config, added firewall rules etc). I have no problem accessing my service from the smartphone's web browser, so I guess it is not a server config issue. But when I do the same request from within my app, I get a 404 response.
Here's the code that sends the request.
client = new HttpClient();
client.BaseAddress = new Uri("http://192.144.1.104:50102/EntityService.svc/");
var builder = new StringBuilder();
builder.Append("player/register?id=");
builder.Append(deviceId.ToString());
builder.Append("&nickname=");
builder.Append(nickname);
var request = new HttpRequestMessage(HttpMethod.Get, builder.ToString());
var response = await client.SendAsync(request);
var dataString = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultDTO>(dataString);
I want to point this out once again, when I copy the formed request link in the phone's web browser, it works fine. I have no idea why it gives me 404 in the application. Does anyone know what's the reason for this?
Thanks in advance.
P.S. I have checked, and IIS Express did not log any requests that are sent from the app.
P.P.S. In the appmanifest, Internet (Client/Server) capability is checked, so it shouldn't be an application permission issue.
Related
I've connected my bot application to the direct line API which is published with Azure. I am currently testing the application with a command line client application, the bot framework emulator, and the dev.botframework.com homepage for my bot.
Everything works correctly until I attempt to submit a GET request to a REST API. I've tested the GET API request in a separate project and it works correctly and the GET request worked prior to implementing the direct line channel. Is there anything I need to be aware of when making http requests with the direct line on the bot side?
Code in question
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", headerParam);
var response = client.GetAsync(new Uri("someUrl.com/api/v1/auth")).Result;
string content = response.Content.ReadAsStringAsync().Result;
var jo = JObject.Parse(content);
this.token = jo["Result"]["Token"].ToString();
}
await context.PostAsync(this.token);
the line that actually causes the failure is
var response = client.GetAsync(new Uri("someUrl.com/api/v1/auth")).Result;
Also is there an easier way to debug a project when it's published to azure and running direct line API?
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions ipaddress
I have tried to invoke my custom REST API within my bot application back-end, then I could leverage Remote debugging web apps to retrieve the result from my bot application hosted on Azure web app as follows:
After searching for the related issue, I found that there be limitation for the number of sockets of your current app service plan when creating the new outgoing connections. You could try to scale up your App Service plan or create a new web app to isolate this issue. For more details, you could refer to this similar issue and this blog.
I have two applications.
Both on the same server
Both running as the same service account
Both require windows Auth
I'm trying to use HttpClient to get from one app to the other with a simple post request; however, the identity doesn't seem to get used.
What I'm using looks like this:
var testIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
var handler = new HttpClientHandler()
{
UseDefaultCredentials = true
};
using (var client = new HttpClient(handler))
{
//...
HttpResponseMessage respose = client.PostAsJsonAsync("api/controller/Method", request);
response.EnsureSuccessStatusCode(); // Exception here!
//...
}
I've verified testIdentity is the service account I want to be running as, but it doesn't seem to make it. I always get a 401 response back.
I've also tested the application sending the request locally (but same domain), and the WebAPI on the server, but that doesn't work either (same 401 response).
If I have both applications local then it works as expected.
Any idea what I may be missing?
Little hesitant to accept this as the answer as I don't know the underlying cause yet; however, the issue I ran into was fixed by impersonating an account on a different domain.
I have created a mobile app in C# Xamarin. I have consumed a webapi hosted on my local system through this app.
It runs on my local xamarin studio.
But it does not work when the app is installed on any Phone over same network.
Code is:
**
var request = new RestRequest ("/api/values", Method.GET);
var client = new RestClient (#"http://anuj2819:90");
client.ExecuteAsync (request, response => {
GetName (response.Content);
});
**
if I use any api hosted on internet such as
**
var request = new RestRequest ("/posts/1", Method.GET);
var client = new RestClient (#"http://jsonplaceholder.typicode.com");
**
it works on the app on phone as well.
Please suggest.
I had the same problem. The way I solved it was by using the IP address of my computer
public const string APIBaseAddress = "http://192.168.1.64/api/";
and opening the firewall on my computer to receive http requests
I have a rest application sitting on an IIS server (on the public internet) with a configuration as follows:
IP Address: A.B.C.D
Host Header: something-not-public-dns.example.com
(The entry isn't in the public dns simply because it doesn't have to be. This isn't merely security by obscuring host headers.)
In order to get my client to connect to the application, I simply add an entry in my hosts file:
A.B.C.D something-not-public-dns.example.com
With the hosts file entry everything works great.
The problem is one of my clients is sitting inside of an ASP.NET web application, and I cannot modify the hosts file for the web server the application resides on.
Thus my question- is it possible to spoof a hosts file entry inside of a web application?
I was thinking of something like this:
string url = "something-not-public.example.com/myservice/mymethod";
var client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/json";
// Set the destination IP for this request here!
string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(MyObject);
string response = client.UploadString(url, json);
I would consider the above example request level spoofing, which would be great, but I'm also curious to know if application level spoofing could be done as well. This way the application could set up the host entries and all requests made from within that application would use them.
You're going about this the wrong way around - instead of trying to setup a mapping from the domain name to the IP address you should simply make the request to the IP and explicitly override the Host header of your HTTP request with the domain name you want to use:
string url = "A.B.C.D/myservice/mymethod";
var client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.Headers[HttpRequestHeader.Host] = "something-not-public.example.com";
I'm using HttpClient from System.Net.Http on nuget to make a request from a module (assembly) written in c#. This needs to work with a legacy application in Windows XP so we're using .Net Framework 4.0.
I can successfully send a https request to our server from my Windows 10 machine; however, when I test it from Windows XP in a VM, I get a fault. I can request websites like https://google.com but our https site causes a fault. On top of all this, the res.StackTrace is null! The Message I get from obj.Exception.InnerException is An error ocurred while sending the request. I can however get to our site in a browser in the VM without trouble. So why can't I get a StackTrace? Could this be some kind of ssl trust issue (our site has an ssl certificate from godaddy)?
var client = new HttpClient();
client.BaseAddress = new Uri(SERVER_BASE_URL); // https://...
// Works when BaseAddress="https://google.com" but not our https site
return client.GetAsync("/").ContinueWith(res =>
{
if (res.IsFaulted)
// res.StackTrace is empty >:(
MessageBox.Show("Faulted");
else
MessageBox.Show("Success");
});