Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to access secure soap web service basic authentication in Windows Phone 7
- at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
- at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass2.<EndGetResponse>b__1(Object sendState)
- at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
- at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
- at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
- at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
- at System.Delegate.DynamicInvokeOne(Object[] args)
- at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
- at System.Delegate.DynamicInvoke(Object[] args)
- at System.Windows.Threading.Dispatcher.<>c__DisplayClass4.<FastInvoke>b__3()
- at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
- at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
- at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
- at System.Delegate.DynamicInvokeOne(Object[] args)
- at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
- at System.Delegate.DynamicInvoke(Object[] args)
- at System.Windows.Threading.DispatcherOperation.Invoke()
- at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
- at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
- at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
- at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
- at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
- using System;
- using System.Text.RegularExpressions;
- using System.Xml.Serialization;
- using System.Collections.ObjectModel;
- namespace MyWP7App
- {
- [XmlRoot("root")]
- public class Categories
- {
- [XmlArray("Categories")]
- [XmlArrayItem("Category")]
- public ObservableCollection<Category> Collection { get; set; }
- }
- }
- public class Category
- {
- [XmlAttribute("ID")]
- public int ID { get; set; }
- [XmlAttribute("SubCategories")]
- public int SubCategoriesCount { get; set; }
- [XmlElement("Name")]
- public string Name { get; set; }
- [XmlArray("SubCategories")]
- [XmlArrayItem("SubCategory")]
- public ObservableCollection<SubCategory> Collection { get; set; }
- }
- using System;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Xml.Serialization;
- using Microsoft.Phone.Controls;
- using System.Xml.Linq;
- namespace MyWP7App
- {
- public partial class CategoriesPage : PhoneApplicationPage
- {
- private ObservableCollection<Category> itemsSource;
- public ObservableCollection<Category> ItemsSource
- {
- get
- {
- return this.itemsSource;
- }
- set
- {
- this.itemsSource = value;
- }
- }
- private static MyService.MobileServiceSoapClient Service = null;
- public PanoramaMainPage()
- {
- InitializeComponent();
- if (null == ItemsSource)
- GetCategories();
- else
- imtListBox.ItemsSource = this.ItemsSource;
- }
- private void GetCategories()
- {
- Service = new MyService.MobileServiceSoapClient();
- // I tried to do the following when the service is secure, but I had the same error:
- // Service.ClientCredentials.UserName.UserName = "Username";
- // Service.ClientCredentials.UserName.Password = "Password";
- Service.GetCategoriesCompleted += new EventHandler<MyService.GetCategoriesCompletedEventArgs>(Service_GetCategoriesCompleted);
- Service.GetCategoriesAsync();
- }
- void Service_GetCategoriesCompleted(object sender, MyService.GetCategoriesCompletedEventArgs e)
- {
- try
- {
- if (e.Result == null || e.Error != null)
- {
- MessageBox.Show("There was an error downloading the XML-file!");
- }
- if (!e.Cancelled)
- {
- XmlSerializer serializer = new XmlSerializer(typeof(Categories));
- XDocument document = XDocument.Parse("<root>" + e.Result.ToString() + "</root>");
- Categories arts = new Categories();
- arts = (Categories)serializer.Deserialize(document.CreateReader());
- this.ItemsSourceListBox = arts.Collection;
- imtListBox.ItemsSource = this.Items1Source;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- Service.Abort();
- }
- }
- using (OperationContextScope contextScope = new OperationContextScope(svc.InnerChannel))
- {
- byte[] bc = System.Text.Encoding.UTF8.GetBytes(@"username" + ":" + "password"); // the string passed after basic:
- HttpRequestMessageProperty httpProps = new HttpRequestMessageProperty();
- httpProps.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(bc);
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpProps;
- // call the service.
- }
Add Comment
Please, Sign In to add comment