I am trying to consume Java REST Webservice in windows phone 8.But it is always giving 404 (page not found) exception (system.net.http.httpexception).That means not able to connect to webservice.
Following is the client code which i used for consuming webservice.
try
{
HttpClient http = new HttpClient();
String result = await http.GetStringAsync("http://192.168.0.56:8078/sample/page/name");
MessageBox.Show(result);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
Please help.Thanks in advance.
Issue solved.Emulator was not able to connect to internet,which was the problem.I tried in windows phone and its working fine.Thanks #akshay2000.
Check your Network Adapters and Verify that there are Hyper-V in their names or 'v' prefixes on the Adapter names, if there are you should check if they are enabled, and enable them if disabled.
If you have nothing like that you should repair the sdk, and that will fix the issue.
Related
I am not able to figure out why my code runs fine on my local but doesn't on azure functions.
This is the code snippet
using (var client = new WebClient ())
{
log.LogInformation($"Fetching html from {url}");
try
{
var response = client.DownloadString(url);
baseHtmlBasePageList.Add(response);
}
catch(Exception ex)
{
log.LogError(ex.Message);
}
}
The URL I am trying to hit is https://www.redfin.com/zipcode/20171.
I am trying to determine where the issue could be.. like
Is Redfin able to differentiate between a request coming from Azure vs my local machine and respond differently?
Is it some setting on Azure that I need to set explicitly?
The code/function itself is very simple. Its a function that takes url like the example mentioned above, fetches the html by calling the DownloadString(url) method and returns the first 20 chars from the returned string.
I do understand that WebClient is deprecated but can we say for certain that that is why the behavior is not consistent between my local machine and Azure?
I'm really new in Xamarin development, and I just tried Xamarin.Forms to Develop Android & iOS App with shared Code, and what I'm trying to do here is to get data from API with Plugin.RestClient NuGet package.
Here's my MainViewModel.
public MainViewModel(){
InitializeDataAsync();
}
public async Task InitializeDataAsync(){
var employeeServices = new EmployeeServices();
EmployeesList = await employeeServices.getEmployeesAsync();
}
And here's my Services
public async Task<List<Employee>> getEmployeesAsync(){
RestClient<Employee> restClient = new RestClient<Employee>();
var employeeList = await restClient.GetAsync("http://localhost:3000/employee");
return employeeList;
}
And this is my RestClient
public async Task<List<T>> GetAsync(string WebServiceUrl){
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync(WebServiceUrl);
Debug.WriteLine(WebServiceUrl);
Debug.WriteLine(json);
var taskModels = JsonConvert.DeserializeObject<List<T>>(json);
return taskModels;
}
The code works fine on my iPhone Emulator. I can see my Debug for the url and json response. But on my Android Emulator there's nothing on the list. I can't even find my Debug for url and json response, I already checked my Application Output and my Device Log (I used Xamarin Studio for Mac btw).
I also already add internet permission on my Android Manifest.
What should I do?
You can only access localhost on your local machine. You need to change localhost to the IP address of the machine on which your api is hosted.
So the api endpoint for
http://localhost:3000/employee
should be something like
http://192.168.0.5:3000/employee
If you are getting a timed out error then it's probably because "localhost" to the Android OS means the phone itself, which is probably not where you're not running the web server. There are some special IP addresses you can use while testing with Android emulators to reach the host OS:
The Google emulators allow you to reach the host OS from 10.0.2.2.
The Microsoft Android emulator allows you to reach the host OS from 169.254.80.80.
You could try changing your URL based on the type of emulator you are using. Alternatively, you can plugin your workstations IP address instead, but this is less desirable because it can change.
If this doesn't allow you to reach the server then you may consider looking at any firewalls to see if your traffic is being blocked.
I have windows phone 8.1 silverlight application where I want to receive Notfications using the new framework, WNS.
I have in the package.appxmanifest: <identity name="4657xxxxxxx" publisher="CN=xxxxx" version="1.0.0.0"/> and added it to the Mobile Service Hub.
For this I have removed old references to MPNS usings, and added the following for WNS:
using Windows.UI.Notifications;
using Windows.Networking.PushNotifications;
using Windows.UI.StartScreen;
This resulted in a new way of getting the channelURI:
public static PushNotificationChannel CurrentChannel { get; private set; }
public async static Task<bool> UploadChannel()
{
bool newChannel = false;
var channel = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var settings = Windows.Storage.ApplicationData.Current.LocalSettings.Values;
object oldChannel;
settings.TryGetValue("channelURI", out oldChannel);
if ((oldChannel as PushNotificationChannel).Uri != CurrentChannel.Uri)
{
settings.Add("channelURI", CurrentChannel);
newChannel = true;
}
try
{
await App.MobileService.GetPush().RegisterNativeAsync(channel.Uri);
}
catch (Exception exception)
{
CurrentChannel.Close();
HandleRegisterException(exception);
}
CurrentChannel.PushNotificationReceived += CurrentChannel_PushNotificationReceived;
return newChannel;
}
private static void HandleRegisterException(Exception exception)
{
MessageBox.Show("error - retry pushchannel");
}
Additionally I removed the ID_CAP_PushNotification based on microsofts update info
I do not get a channel I get an error:
The application does not have the cloud notification capability. (Exception from HRESULT: 0x803E0110)
solution
Searched for the error and found this link, This can be solved as stated in the answer below by accessing package.appxmanifest and enable Internet (Client & Server).
ERROR 2
Then it the UploadChannel()function should work. However the Register API call await App.MobileService.GetPush().RegisterNativeAsync(channel.Uri); results in an error on the server:
Message='Could not register with the 'mpns' platform. Error received: 'Unsupported channel uri: 'https://db3.notify.windows.com . . . .
The error makes sense but I have no idea on how to solve it.
Ekstra
On the server I can subscribe with the URI, and receive notifications. But not on the client. Is this how it should be or?
On Client side:
Ideally, to use WNS, you should remove all references to MPNS from WMAppManifest.xml and add the info provided by Windows Store to your package.appxmanifest.
I understand that you are migrating from WP8 to WP8.1. So in your package.appxmanifest, edit the code so that it looks like this:
<Identity Name="4657xxxxxxx" Publisher="CN=xxxxx" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="xxxx" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
Note: The 0s in the PhonePublisherId are intentional. I have no idea why, but the app wouldn't work when I did not provide them as such.
You are doing the channel uri request right:
PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
string channelUri = channel.Uri;
You should also set the Internet (Client & Server) capability in Package.appxmanifest to be checked.
To receive notifications on the client, you should intercept the received notification as described here:
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709907.aspx
On Server Side:
The error "Unsupported Channel URI" occurs because you are using the MPNS methods to process the URI in your Azure server.
Refer here for the proper way to do it using WNS: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-universal-dotnet-get-started-push/
Adding internetClient capability should resolve this error.
Creating a notification channel results in an WPN_E_CLOUD_INCAPABLE error
Cause: Your app has not declared the Internet capability in its app manifest (package.appxmanifest).
Fix: Ensure that your app manifest has declared Internet capability. In the Visual Studio manifest editor, you will find this option under the Capabilities tab as Internet (Client).
The .NET client SDK for Azure Mobile doesn't currently support using WNS in Windows Phone 8.1 Silverlight applications. You have to use MPN or change your project to a NON-silverlight project type.
Reference (see Elio's response): https://social.msdn.microsoft.com/Forums/azure/en-US/1aa29977-a26d-4054-89b2-c853cbd35c18/wns-for-windows-phone-silverlight-81-apps-with-azure-mobile-services?forum=azuremobile
I'm not sure if they'll update it to support this as Silveright for 8.1 is primarily for backwards compat with existing apps and not many of them were using Mobile Services as it is newer.
In my case, select the ARM platform in my project settings did the trick. I was in "Any CPU".
I am trying to call a WCF service via a windows 8.1 app that I have created. But when I call it I get the exception:
One or more errors occurred
Unable to connect to the remote server
There was no endpoint listening at http://theRequestedService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
An attempt was made to access a socket in a way forbidden by its access permissions [theIPAddress:thePortNumber]
I have reviewed the settings of the service and they seem to be okay and have checked to see if I can access it the following ways:
access via browser (successful)
access via console application (successful)
run Fiddler4 and my windows 8 app (successful)
access directly from the app (falied)
NB: I ran fiddler4 to try and get an error message that would lead me to the solution
I thought I may have altered a setting in my project, so created a fresh test project, but I get the same issue.
The exception messages seem self explanatory so why am I able to successfully connect via the other methods but not through the app? and what steps need to be taken to resolve this issue?
MY CONNECTION CODE (if this helps with solving the problem)
class ConnectionManager
{
public static ConnectionStatus IsConnected()
{
ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
ConnectionStatus result = (connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess) ? ConnectionStatus.NotSet : ConnectionStatus.NoInternet;
if (result == ConnectionStatus.NotSet)
{
CommonFunctionsClient client = new CommonFunctionsClient();
try
{
client.ChannelFactory.Endpoint.Binding.SendTimeout = TimeSpan.FromMilliseconds(3000);
if (client.PingAsync().Result)
result = ConnectionStatus.Connected;
else
result = ConnectionStatus.NoWCF;
}
catch (Exception ex)
{
throw ex;
//result = ConnectionStatus.NoWCF;
}
}
return result;
}
}
public enum ConnectionStatus
{
Connected,
NoWCF,
NoInternet,
NotSet
}
For me to resolve this issue I downloaded HtmlAgilityPack
HtmlAgilityPack found here from nuGet
I guess the error was due to an issue with x-paths.
I admit this is far from a complete answer but it may help someone resolve their issue if they come across the same thing.
Hopefully someone could provide a reason this solution worked, or a better solution to this issue.
I'm trying to debug an application that is making a WebRequest synchronously, ie.:
HttpWebRequest req = WebRequest.Create(new Uri("http://www.stackoverflow.com/")) as HttpWebRequest;
IAsyncResult res = req.BeginGetResponse(callback => { }, req);
while (!res.IsCompleted)
{
System.Threading.Thread.Sleep(100);
}
// Doesn't matter what's here, as `res.IsCompleted` never returns true
This is just to check that some of the application logic is "right", but it's getting stuck, with the IAsyncResult never reporting itself as complete.
To check, things, I tried to use Internet Explorer on the emulator, but found that is unable to find any webpages (including the built in favourites), which makes me think that the emulator is trying to use a specific network interface on my laptop, but there doesn't seem to be any way to configure it, or which interface to use? I have a suspicion that it may be trying to use a VPN interface, or a virtual adaptor like the one for VirtualBox. So, how can I configure it? additionally, would you expect requests made by the emulator to show up in Fiddler?
For the record, NetworkInterface.GetIsNetworkAvailable() returns true;
UPDATE:
It appears that updating my graphics driver (and associated reboot) allowed the emulator to access the real network (or at least guess the right adapter); however, res.IsCompleted still doesn't report true (and Fiddler shows the request has completed), so I'm a little confuddled.
Are you using a proxy? The Windows Phone emulator is tied to the currently active Internet Connection, as well as the proxy settings. Make sure those are set up correctly. Also, there might be a firewall blocking Internet access for XDE - check the settings too.
I would recommend getting Fiddler. Attempt to configure it to capture emulator traffic and see what information you can get from there.