- codes.zip
- Codes
- ExtendingWCFPartI
- ExtendingWCFPartI.Client
- ExtendingWCFPartI.Common
- ExtendingWCFPartI.Service
- ExtendingWCFPartI.sln
- ExtendingWCFPartI.WcfExtentions
|
using System;
using System.IO;
using System.Windows;
using System.ServiceModel;
using ExtendingWCFPartI.WcfExtentions;
using ExtendingWCFPartI.Common.Services;
using System.Text;
namespace ExtendingWCFPartI.Client
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
private static readonly string ExternalConfigPath = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + "..\\..\\WcfClientConfiguration.xml");
public Window1()
{
InitializeComponent();
}
private void GetCustomerList()
{
try
{
var proxy = WcfClientHelper.GetProxy<ICustomerService>(ExternalConfigPath);
DataContext = proxy.GetCustomers();
}
catch(EndpointNotFoundException enfe)
{
MessageBox.Show("Please run the service before. " + Environment.NewLine + enfe.Message);
}
catch(Exception exception)
{
MessageBox.Show(exception.Message);
}
}
private void btnGetCustomers_Click(object sender, RoutedEventArgs e)
{
GetCustomerList();
}
private void btnGetException_Click(object sender, RoutedEventArgs e)
{
GetExceptionFromService();
}
private void GetExceptionFromService()
{
try
{
var proxy = WcfClientHelper.GetProxy<ICustomerService>(ExternalConfigPath);
proxy.GetException();
}
catch (Exception exception)
{
ShowMessage(GetExceptionDetail(exception));
}
}
private string GetExceptionDetail(Exception exception)
{
var sb = new StringBuilder();
sb.Append(string.Format("Exception type: {0}{1}", exception.GetType().FullName, Environment.NewLine));
sb.Append(string.Format("Exception Message: {0}{1}", exception.Message, Environment.NewLine));
var innerException = exception.InnerException;
var counter = 1;
while (null != innerException)
{
sb.Append(string.Format("Inner Exception {0} type: {1}{2}", counter, innerException.GetType().FullName, Environment.NewLine));
sb.Append(string.Format("Inner Exception {0} message: {1}{2}", counter, innerException.GetType().FullName, Environment.NewLine));
innerException = innerException.InnerException;
counter++;
}
sb.Append(string.Format("Stacktrace: {0}", exception.StackTrace));
return sb.ToString();
}
private void ShowMessage(string message)
{
txtMessage.Text = message;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.