I have added the web service to my WPF windows phone store app, when i run my app in emulator it works, but sometime it get creshes cause lack of internet connectivity.
i'm checking my emulator IMEI is registerd or not in database using WCF service on main_pageload event
my code looks like this
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
SchoolWebService.SchoolAppWebServiceSoapClient proxy = new SchoolAppWebServiceSoapClient();
proxy.CheckIMEIRegisteredOrNotCompleted += new EventHandler<CheckIMEIRegisteredOrNotCompletedEventArgs>(proxy_CheckIMEIRegisteredOrNotCompleted);
proxy.CheckIMEIRegisteredOrNotAsync(strIMEI);
}
in this service im checking the mobile IMEI registerd or not. i have checked by debugging the app it goes upto proxy.CheckIMEIRegisteredOrNotAsync(strIMEI);
when it leave the context it throuw the error
An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.ni.dll but was not handled in user code
please suggest me some advice,,,thanks in advance
To check if the Internet connection is available I just simply create a method to check it and execute it then application is launching or page is loading. This method I create in App.xaml.cs:
public bool CheckInternetConnection()
{
bool connection = true;
ConnectionProfile currentConnection = NetworkInformation.GetInternetConnectionProfile();
if (currentConnection == null)
{
connection = false;
}
return connection;
}
Then in some page_loaded event I execute it:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
bool connection = ((App)Application.Current).CheckInternetConnection();
if (connection == false)
{
MessageBox.Show("Internet connection is not available", "Internet connection", MessageBoxButton.OK);
Application.Current.Terminate();
}
}
Now then a client don't have the Internet connection available it won't crash, but it will show a message for the user. I hope it will help.
Related
My scenario is as follows. I have an Android Emulator which is hosting an EmbedIO web server through an App. When I try to access the URL to the web server from the host machine's (Mac) browser I receive ERR_EMPTY_RESPONSE error.
I have issued the following port forwarding commands through ADB:
adb forward tcp:8080 tcp:8080
In the browser I am navigating to: http://localhost:8080/api/ChangeBackGround
and the Android emulator web server is listening on: http://10.0.2.16:8080/api/ChangeBackGround
Here is the code that starts the web server in the Xamarin Forms App (runs on Android Emulator):
public static class WebServerFactory
{
public static WebServer CreateWebServer<T>(string url, string baseRoute)
where T : WebApiController, new()
{
var server = new WebServer(url)
.WithWebApi(baseRoute, api => api.WithController<T>());
// Listen for state changes.
server.StateChanged += (s, e) => Debug.WriteLine($"WebServer New State - {e.NewState}");
return server;
}
}
public class EventController : WebApiController
{
[Route(HttpVerbs.Get, "/ChangeBackGround")]
public void ChangeBackGround()
{
Device.BeginInvokeOnMainThread(() =>
{
App.Current.MainPage.BackgroundColor = Color.Green;
});
}
}
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
private WebServer _WebServer;
protected override void OnStart()
{
var localIPAddress = GetLocalIPAddress();
var url = $"http://{localIPAddress}:8080";
Task.Factory.StartNew(async () =>
{
_WebServer = WebServerFactory.CreateWebServer<EventController>(url, "/api");
await _WebServer.RunAsync();
});
((MainPage)MainPage).Url = url;
}
private string GetLocalIPAddress()
{
var IpAddress = Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault();
if (IpAddress != null)
return IpAddress.ToString();
throw new Exception("Could not locate IP Address");
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}
The scenario currently works on the iOS simulator and an Android physical device. But I always get ERR_EMPTY_RESPONSE even when I've setup the port forwarding rules.
Any help would be much appreciated.
Please first make sure your android emulator could connect internet properly.
If the problem perisist, you can try the following methods:
Method 1:
1.start your Command prompt by runing as an admistrator;
2.Run the following commands in sequence:
netsh int ip reset c:\resetlog.txt
netsh winsock reset
ipconfig /flushdns
exit
Method 2: (If method 1 didn't work,try modthod 2)
Open your Control Panel -->NetWork and Internet-->Network and Sharing Center-->Change adapter settings-->right click Ethenet and click Properties-->select Internet Protocol 4-->click Properties -->using the following NDS server addresses
Fill in the following configuration:
Preferred NDS Server: 1.1.1.1
Alternate NDS Server: 1.0.0.1
Method 3: (If above methods didn't work,try modthod 3)
Open Settings in your PC-->Open NetWork and Internet-->click Nnetwork reset-->press Reset Now
Note:
For more details, you can enter keywords How to fix "ERR_EMPTY_RESPONSE" Error [2021] in your browser and then you will find relative tutorail.
You should have you service listening on either one of these IPs:
127.0.0.1: The emulated device loopback interface (preferred, I don't think you have reasons to use a different one)
10.0.2.15: The emulated device network/ethernet interface
See https://developer.android.com/studio/run/emulator-networking#networkaddresses
I have WPF application that connects to WebAPI, which runs SignalR. Everything works fine, until Internet connection is lost by client.
When it happens, SignalR does not fire any events on client side (StateChanged, Error, Reconnecting, Closed etc.)
Code is pretty straightforward
public HubConnection _hubConnection;
IHubProxy _proxy;
public async Task ConnectToHub(string hubUrl, string hubName)
{
_hubConnection = new HubConnection(HubURL);
_hubConnection.Reconnecting += hubConnection_Reconnecting;
_hubConnection.Closed += _hubConnection_Closed;
_hubConnection.StateChanged += _hubConnection_StateChanged;
proxy = hubConnection.CreateHubProxy(hubName);
await _hubConnection.Start();
}
void _hubConnection_StateChanged(Microsoft.AspNet.SignalR.Client.StateChange obj)
{
throw new NotImplementedException();
}
void _hubConnection_Closed()
{
throw new NotImplementedException();
}
void _hubConnection_Reconnectig()
{
throw new NotImplementedException();
}
SignalR version 2.2.0
Thanks for help
Try subscribing to the Error event. Depending on "how" the connection is lost, I don't think some of the other events will get fired.
_hubConnection.Error += (e=>{ ... });
Transport type on SignalR was set automatically to ServerSentEvents instead of WebSockets (Server admin didn't turn it on). Turned out that only with Websockets we can get connection-related events on .Net-client, when connection is lost.
According to http://www.asp.net/signalr/overview/getting-started/introduction-to-signalr
WebSocket is the only transport that establishes a true persistent, two-way connection between client and server.
I have the following code snippet that run with IIS Express of VS2012. It is able to send out email and working fine with smtp server.
Then deployed it as New Application on IIS 7. When I run it, I am getting the error “System.Net.Sockets.SocketException: A system call has failed 11.29.83.49:25” .
Do you have any idea what causing the error?
Do I miss something to configure IIS server to work with smtp server?
protected void Page_Load(object sender, EventArgs e)
{
System.Net.Mail.MailMessage _message = new System.Net.Mail.MailMessage();
_message.Subject = "Hi Testing";
_message.SubjectEncoding = System.Text.Encoding.UTF8;
_message.From = new System.Net.Mail.MailAddress("sender#gmail.com","Test");
_message.To.Add(new System.Net.Mail.MailAddress("receiver#gmail.com", "Test"));
System.Net.Mail.AlternateView _content_view = System.Net.Mail.AlternateView.CreateAlternateViewFromString("Message Body");
_message.AlternateViews.Add(_content_view);
sendEmailMessage(_message);
}
public void sendEmailMessage(System.Net.Mail.MailMessage message)
{
getClientFromConfig().Send(message);
}
private static System.Net.Mail.SmtpClient getClientFromConfig()
{
System.Net.Mail.SmtpClient _client = new System.Net.Mail.SmtpClient();
_client.Host = "host name/ip here";
_client.Port = 25;
return _client;
}
Could anyone please suggest to get it work?
I think the reason is firewall.
Open IIS Manager ->Application Pool and select your pool then click advanced settings.
Change your Identity as
Network Service
-below the process model
I've spent a lot time trying to figure this one out, but without luck - so I will try to post the question here.
I am running 2 ASP.NET websites on the same server. Both websites are running on IIS 7.5 + .NET 4. The sites use the SSRS Report Viewer to show reports from an another server.
We recently moved both the websites and RS to new servers (switching from RS 2005 to RS 2008 and switching from IIS 7.0 to IIS 7.5). However, after moved to the new servers, one of the websites are unable to view the reporting services, as we get the following error:
request failed with HTTP status 401
The strange thing is, that the Report Viewer is configured exactly the same way in the two websites (simply copy pasted between the two). Further, using the "working website", we are able to view the reports belonging to both websites - and using the other website, we are unable to view any of the reports.
The authorization looks like this in both cases:
Credentials:
[Serializable]
public sealed class ReportServerCreditentials : IReportServerCredentials
{
public WindowsIdentity ImpersonationUser
{
get { return null; }
}
public ICredentials NetworkCredentials
{
get
{
string userName = ConfigurationManager.AppSettings["ReportViewerUser"];
string password = ConfigurationManager.AppSettings["ReportViewerPassword"];
string domain = ConfigurationManager.AppSettings["ReportViewerDomain"];
return new NetworkCredential(userName, password, domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
{
authCookie = null;
userName = null;
password = null;
authority = null;
return false;
}
}
Report Viewer usage
public partial class ReportServicesViewer : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
string reportingFolder = ConfigurationManager.AppSettings["ReportingFolder"];
showReport(string.Format("/{0}/{1}", reportingFolder, Request.QueryString["report"]));
}
}
private void showReport(string reportPath)
{
RevReport.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServer"]);
RevReport.ServerReport.ReportServerCredentials = new ReportServerCreditentials();
RevReport.ServerReport.ReportPath = reportPath;
}
}
In aspx:
<rsweb:ReportViewer ID="RevReport" runat="server" Height="100%" Width="100%" Font-Names="Verdana" Font-Size="8pt" ProcessingMode="Remote" ZoomMode="Percent" ZoomPercent="100"></rsweb:ReportViewer>
Other observations
At one point, we tried to monitor the traffic between the website and RS using Fiddler, but somehow the communication actually worked in this case.
However, when I tried this at a later point, Fiddler gave the following response:
[Fiddler] The socket connection to <servername> failed. <br />ErrorCode: 10061. <br />No connection could be made because the target machine actively refused it 10.0.0.17:443
I am not sure how exactly to interpret this, as we are not using SSL for the Website <-> RS communication.
Any advice would be greatly appreciated.
I had the similar issue when we built new SSRS server. Web application was not able to connect to report server. I was able to solve the issue by doing these:
Enable Kerberos Authentication on the server
Set spn(server principal names) on the server
enable the impersonation in web application
I have the following code:
protected void VLC_Click(object sender, EventArgs e)
{
SecureString password = ConvertStringToSecureString("[password]");
string domain = "";
Process.Start(#"C:\Program Files\VideoLAN\VLC\vlc.exe ", "[username]", password, domain);
}
private SecureString ConvertStringToSecureString(string s)
{
SecureString secString = new SecureString();
foreach (char c in s.ToCharArray())
{
secString.AppendChar(c);
}
return secString;
}
linked to a button on an aspx page running on IIS on my Vista machine. When I click the button in the browser, I can see the process start in task manager but shortly after the process terminates and no vlc window appears at any point.
Is there any way to have the button trigger vlc just as if I was clicking on the .exe in Windows?
I hope you don't expect VLC appearing on the client machine when you do a Process.Start on the server in an ASP.NET application.
It should work if the user that runs asp.net is able to interact with the desktop. On windows services there is a setting one can check for this.