locked
Fault Exeption 1

    Question

  • I got this error faultException1. i got no idea what wrong with it.

    My web service code

    public interface IService
    {

    [OperationContract]
    string GetData(int value);

    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);

    // TODO: Add your service operations here
        [OperationContract]
        string GetEbook(string eTitle);
    }

    public class Service : IService
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
        public string GetEbook(string eTitle)
        {
            string connString = ConfigurationManager.ConnectionStrings["LibraryDB"].ToString();
            string etitle = "Blank";
            try{
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    using (SqlCommand myCommand = new SqlCommand("select eTitle from eBook", conn))
                    //using (SqlCommand myCommand = new SqlCommand("select eTitle from eBook where eBookID ='" + ebookid + "'", conn))
                    {
                        conn.Open();
                        SqlDataReader myReader = myCommand.ExecuteReader();
                        while (myReader.Read())
                        {
                            etitle = myReader[0].ToString();
                        }
                        myReader.Close();
                        conn.Close();
                    }
                }

            }
            catch(SqlException ex)
            {
                if (ex.Data !=null)
                { etitle = "Not found";}
            }

            return etitle;
        }

    My Windows Phone App code 

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                string eTitle = "Windows";
                ServiceReference1.ServiceClient ebookSvc = new ServiceReference1.ServiceClient();
                ebookSvc.GetEbookCompleted += ebook_getEbookCompleted;
                ebookSvc.GetEbookAsync(eTitle);

            }

            void ebook_getEbookCompleted(object sender, ServiceReference1.GetEbookCompletedEventArgs e)
            {
                if (e.Error != null)
                { MessageBox.Show(e.Error.ToString()); }
                else
                {
                    tbTitle.Text = e.Result.ToString();
                }

              
            }

    Saturday, January 17, 2015 8:57 AM

Answers

  • The fault exception usually means something is causing an error the wcf service.  If when you call the wcf service from the phone if the url is localhost change the localhost to your computer's name.

    If you set a break point inside of your wcf service do you hit it?

    Personally if you are creating a service for use with a phone app I think it is a better to use the web api but you can still use wcf if you want.

    Saturday, January 17, 2015 11:27 AM