system.servicemodel.communicationexception。在system.servicemodel.ni.dll中

时间:2013-02-23 04:51:26

标签: wcf c#-4.0 windows-phone-8

我在Windows Phone应用程序中调用WCF服务时遇到此错误。  请为此建议一些解决方案。

示例代码:

   private void Button_Click_1(object sender, RoutedEventArgs e)
   {

       ServiceReference1.ServiceClient myService = new ServiceReference1.ServiceClient();
       if (txtUser.Text.ToString() != null)
       {


           myService.ValidateAsync(txtUser.Text.ToString(), pwdPassword.ToString());
           System.Threading.Thread.Sleep(TimeSpan.FromSeconds(20));
           myService.ValidateCompleted += new EventHandler<ServiceReference1.ValidateCompletedEventArgs>(myService_ValidateCompleted);
       }
       else
       {
           MessageBox.Show("Enter some username or password");
       }
   }

**控制不会显示下一个功能:

  System.ServiceModel.ni.dll中的

system.servicemodel.communicationexception


   private void myService_ValidateCompleted(object sender, ServiceReference1.ValidateCompletedEventArgs e)
   {

       //int a = 0;
       //a = Convert.ToInt32(e.Result);

       if (e.Result== 1)
       {
           MessageBox.Show("Enter");
           // this.NavigationService.Navigate(new Uri("/TilesPage.xaml", UriKind.Relative));
       }
       else if (e.Result == 0)
       {
           MessageBox.Show("Invalid Username or Password");
       }
       else if (e.Result == -1)
       {
           MessageBox.Show("UserName doesn't exists");
       }
       else
       {
           MessageBox.Show("some exception");
       }


   }

1 个答案:

答案 0 :(得分:1)

包括一个捕获块

catch (CommunicationException commProblem)
{
     Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
     Console.Read();     
}