How to use SOAP in windows phone 7 - windows-phone-7

Dont know what to do.
I have all the data i need but dont know how to use it right.
I have started to add a "Service Reference". I added the URL wich is this one: transpawebserviceslive/gateway.asmx
So what i have done now is this. For my click event on my button to verify that the password and username is correct i have done the following and i dont know if i am doing it right here:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
ServiceReference.GatewaySoapClient client = new ServiceReference.GatewaySoapClient();
client.AuthenticateAsync(username.Text,password.Text,sign.Text,password.Text);
client.AuthenticateCompleted += client_AuthenticateCompleted;
}
void client_AuthenticateCompleted(object sender, ServiceReference.AuthenticateCompletedEventArgs e)
{
ServiceReference.AuthenticatedDto test = new ServiceReference.AuthenticatedDto();
if (kund.Text == test.CustomerUser)
{
MessageBoxResult m = MessageBox.Show("Ok", "Ok", MessageBoxButton.OK);
}
else
{
MessageBoxResult m = MessageBox.Show("Wrong", "W", MessageBoxButton.OK);
}
Dont know what i am doing here, whould be nice with some help.

All that you did there is correct. You just have to parse the response and proceed.
void client_AuthenticateCompleted(object sender, ServiceReference.AuthenticateCompletedEventArgs e)
{
if (e.Error == null) //To ensure there is no error in the request
{
if (e.Result.Contains("ERROR"))
MessageBox.Show("Authentication failed", "Ok", MessageBoxButton.OK);
else
MessageBox.Show("Authenticaion success", "Ok", MessageBoxButton.OK);
}
}

Related

C++ GUI write to textBox while using backgroundWorker

I am trying to write to a textBox while having a loop on backgroundworker. I tried using Invoke/BeginInvoke however I couldn't do it. How can I change it to make it work? Here is my code below, thanks in advance.
delegate void backgroundWorker1_DoWorkDelegate(Object^ sender, DoWorkEventArgs^ e);
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
if (textBox1->InvokeRequired)
{
backgroundWorker1_DoWorkDelegate^ action = gcnew backgroundWorker1_DoWorkDelegate(this, &MyForm::Worker);
this->BeginInvoke(action);
}
else
{
textBox1->Text = "a";
} ... }
void Worker(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
{
textBox1->Text = "a";
}

Sitefinity - Remove Session after Logout

I am trying to clear a HttpContext.Current.Session after User logs out of a Sitefinity page.
I saw in this link that you can check the Request.Url but I'm not exactly sure what the implementation is.
This is my current attempt:
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (((System.Web.HttpApplication)(sender)).Request.Url.ToString() == HttpContext.Current.Server.MapPath("~/Sitefinity/Login/DoLogout"))
{
if (HttpContext.Current.Session["Cart"] != null) HttpContext.Current.Session.Remove("Cart");
HttpContext.Current.Session["Cart"] = new List<IQuoteResult>();
}
}
Please let me know if you have any tips or suggestions, or if I'm completely wrong with my logic.
Thanks in advance.
UPDATE:
protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
if (((HttpApplication)(sender)).Request.Url.ToString().Contains("sign_out=true"))
{
if (HttpContext.Current.Session["Cart"] != null)
{
HttpContext.Current.Session.Remove("Cart");
HttpContext.Current.Session["Cart"] = new List<IQuoteResult>();
}
}
}
This is my next attempt at completing the same task but I keep receiving a NullReferenceException...
Note: I've also tried this method in the Application_AcquireRequestState method.
Here is the stack:
[NullReferenceException: Object reference not set to an instance of an object.]
SitefinityWebApp.Global1.Application_PostAcquireRequestState(Object sender, EventArgs e) +137
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +91
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +164
This ended up being my solution:
public bool IsUserLoggingOut { get; set; }
protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
if (((HttpApplication)(sender)).Request.Url.ToString().Contains("/Sitefinity/SignOut"))
{
IsUserLoggingOut = true;
}
if (IsUserLoggingOut && SystemManager.CurrentHttpContext.Session != null)
{
SystemManager.CurrentHttpContext.Session.Remove("Quote");
IsUserLoggingOut = false;
}
}
Looks like Sitefinity has its own SystemManager to access the http context. It worked perfectly.
That's pretty close to how I would do it. The only change I would make is change your url comparison logic to be something like:
if (((System.Web.HttpApplication)(sender)).Request.Url.ToString().EndsWith("/Sitefinity/Login/DoLogout"))
Or potentially use .Contains() instead of EndsWith() -- not sure if there are any query-string parameters or trailing slashes added on the DoLogout action.
This is because Request.Url returns a URL (ex. https://stackoverflow.com/whatever) whereas Server.MapPath() returns a local path (ex. C:\inetpub\wwwroot\whatever), so you wouldn't be comparing apples to apples if you're comparing the two.
Edit:
Something like this should work, just adding a check to see if the session is null
protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
if (((HttpApplication)(sender)).Request.Url.ToString().Contains("sign_out=true"))
{
if (HttpContext.Current.Session != null && HttpContext.Current.Session["Cart"] != null)
{
HttpContext.Current.Session.Remove("Cart");
HttpContext.Current.Session["Cart"] = new List<IQuoteResult>();
}
}
}

Set the query string, but still get NullReferenceException

I want to show the error message on the other page. I got the NullReferenceException, but the query string is set on the page which has error. Would someone tell me what is wrong with my code?
catch (Exception ex)
{
//Dispatcher.BeginInvoke(new Action(() =>MessageBox.Show(ex.StackTrace,"Error!",MessageBoxButton.OK)));
string query=#"/ErrorPage.xaml?msg=" + ex.StackTrace.ToString() ;
Dispatcher.BeginInvoke(new Action(() =>this.NavigationService.Navigate(new Uri(query, UriKind.Relative))));
}
There is the code for showing the error message when the page is loaded on other page
public ErrorPage()
{
InitializeComponent();
string msg = NavigationContext.QueryString["msg"].ToString();
lstMessage.Items.Add(msg);
}
I should put my code into the MainPage_Load method. It works.
public ErrorPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show(CMSPhoneApp.App.GlobalVariables.strNofifyEmailSubject,
"Report Error", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
//according to the serach it works on real devices (not on the emulator)
//the reason the EmailComposer not pop up because can't set up an email account on the emulator
EmailComposeTask emailcomposer = new EmailComposeTask();
emailcomposer.To = CMSPhoneApp.App.GlobalVariables.reportAddress;
emailcomposer.Subject = CMSPhoneApp.App.GlobalVariables.strNofifyEmailSubject;
emailcomposer.Body = CMSPhoneApp.App.GlobalVariables.errorMsg;
emailcomposer.Show();
}
else
{
App.GoBack();
}
}

How to persist IsolatedStorageSettings after terminate the application

How to retain the saved isolatedstoragesettings while at application launch
I used exception for termination on backevents :
protected void _BackKeyPress(object sender, CancelEventArgs e)
{
if (MessageBox.Show("Do you want to close the application?", "Q", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Add("key2", "33r4 ");
}
else
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("Key"))
{
IsolatedStorageSettings.ApplicationSettings["Key"] = App.Current.ViewModel;
}
else
{
IsolatedStorageSettings.ApplicationSettings.Add("Key", App.Current.ViewModel);
}
throw new Exception("ExitApplication");
}
}
I try to save the viewmodel which declares in app.xaml.cs, but cant able to get the isolatedstorage settings value in it, at launch. But It compiles and run successfully.
You need to call the IsolatedStorageSettings.Save method:
protected void _BackKeyPress(object sender, CancelEventArgs e)
{
if (MessageBox.Show("Do you want to close the application?", "Q", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Add("key2", "33r4 ");
IsolatedStorageSettings.Save();
}
else
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("Key"))
{
IsolatedStorageSettings.ApplicationSettings["Key"] = App.Current.ViewModel;
}
else
{
IsolatedStorageSettings.ApplicationSettings.Add("Key", App.Current.ViewModel);
}
IsolatedStorageSettings.Save();
throw new Exception("ExitApplication");
}
}

PostBack and session values. Why after button is clicked and session created postback still show null

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblPostBack.Text = " Text created first time";
}
else
{
if (Session["Counter"] == null)
{
lblPostBack.Text = "PostBack x however strange becasue if is postback it's mean somebody clicked button and session value has been created";
}
else
{
lblPostBack.Text = "PostBack x should be count here";
}
}
}
protected void cmd_Click(object sender, EventArgs e)
{
int _counter;
if (Session["Counter"] == null)
{
_counter = 1;
}
else
{
_counter = (int)Session["Counter"] + 1;
}
Session["Counter"] = _counter;
lblPostBack.Text += "Counter: " + _counter.ToString();
}
Assuming this is ASP.NET: It's because the Click event on your button fires after the Load event on your page, so the session has not been set.
MSDN on the page lifecycle might be good reading - the button click is a "postback event" in the table in that document.
If I've got the wrong end of the stick, please explain what messages you get after the button clicks, and what you were expecting. Some framework and language tags on the question might not go amiss, either.
Ok it works, just FF mess up
I have added following method and works fine.
private int _counter;
protected void Page_Load(object sender, EventArgs e)
{
(...)
protected void Page_PreRender(Object sender, EventArgs e)
{
Session["Counter"] = _counter;
}

Resources