none
Error : The operation is not supported in wcf test client because it uses type Author

    Question

  • I have very simple service that does the following:

    Service.svc.cs

            public Author SelectAuthor(string value)
            {
                EFTestEntities entities = new EFTestEntities();
    
                Author selectedAuthor = (from a in entities.Authors
                                         where a.AuthorCity == value
                                         select a).First();
    
                return selectedAuthor;
            }
    iService.cs
     [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            Author SelectAuthor(string value);
        }

    The Author type was generated by Entity Framework when I created the model from the database. Thus, the Author type should comply with Serialization and I should be able to get the return type.

    I am quite new to WCF so, please help me clear this problem. Thanx in advance.

    Don't miss to 'Vote As Helpful' or 'Mark As Answer' a deserving post.

    Tuesday, December 18, 2012 1:32 PM

Answers

All replies

  • you have to create Author Entity as DataContract.

    Regards

    Mohit

    Tuesday, December 18, 2012 1:46 PM
  • you have to create Author Entity as DataContract.

    Regards

    Mohit

    It already has those attributes in the generated classes:

        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmEntityTypeAttribute(NamespaceName="DSTestModel", Name="Author")]
        [Serializable()]
        [DataContractAttribute(IsReference = true)]
        public partial class Author : EntityObject
        {
            #region Factory Method
        
            /// <summary>
            /// Create a new Author object.
            /// </summary>
            /// <param name="reference">Initial value of the Reference property.</param>
            public static Author CreateAuthor(global::System.String reference)
            {
                Author author = new Author();
                author.Reference = reference;
                return author;
            }
    
            #endregion
            #region Primitive Properties
        
            /// <summary>
            /// No Metadata Documentation available.
            /// </summary>
            [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
            [DataMemberAttribute()]
            public global::System.String AuthorCity
            {
                get
                {
                    return _AuthorCity;
                }
                set
                {
                    OnAuthorCityChanging(value);
                    ReportPropertyChanging("AuthorCity");
                    _AuthorCity = StructuralObject.SetValidValue(value, true);
                    ReportPropertyChanged("AuthorCity");
                    OnAuthorCityChanged();
                }
            }
            private global::System.String _AuthorCity;
            partial void OnAuthorCityChanging(global::System.String value);
            partial void OnAuthorCityChanged();
        
            /// <summary>
            /// No Metadata Documentation available.
            /// </summary>
            [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
            [DataMemberAttribute()]
            public global::System.String AuthorId
            {
                get
                {
                    return _AuthorId;
                }
                set
                {
                    OnAuthorIdChanging(value);
                    ReportPropertyChanging("AuthorId");
                    _AuthorId = StructuralObject.SetValidValue(value, true);
                    ReportPropertyChanged("AuthorId");
                    OnAuthorIdChanged();
                }
            }
            private global::System.String _AuthorId;
            partial void OnAuthorIdChanging(global::System.String value);
            partial void OnAuthorIdChanged();
        
            /// <summary>
            /// No Metadata Documentation available.
            /// </summary>
            [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
            [DataMemberAttribute()]
            public global::System.String AuthorLName
            {
                get
                {
                    return _AuthorLName;
                }
                set
                {
                    OnAuthorLNameChanging(value);
                    ReportPropertyChanging("AuthorLName");
                    _AuthorLName = StructuralObject.SetValidValue(value, true);
                    ReportPropertyChanged("AuthorLName");
                    OnAuthorLNameChanged();
                }
            }
            private global::System.String _AuthorLName;
            partial void OnAuthorLNameChanging(global::System.String value);
            partial void OnAuthorLNameChanged();
        
            /// <summary>
            /// No Metadata Documentation available.
            /// </summary>
            [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
            [DataMemberAttribute()]
            public global::System.String AuthorFName
            {
                get
                {
                    return _AuthorFName;
                }
                set
                {
                    OnAuthorFNameChanging(value);
                    ReportPropertyChanging("AuthorFName");
                    _AuthorFName = StructuralObject.SetValidValue(value, true);
                    ReportPropertyChanged("AuthorFName");
                    OnAuthorFNameChanged();
                }
            }
            private global::System.String _AuthorFName;
            partial void OnAuthorFNameChanging(global::System.String value);
            partial void OnAuthorFNameChanged();
        
            /// <summary>
            /// No Metadata Documentation available.
            /// </summary>
            [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
            [DataMemberAttribute()]
            public global::System.String Reference
            {
                get
                {
                    return _Reference;
                }
                set
                {
                    if (_Reference != value)
                    {
                        OnReferenceChanging(value);
                        ReportPropertyChanging("Reference");
                        _Reference = StructuralObject.SetValidValue(value, false);
                        ReportPropertyChanged("Reference");
                        OnReferenceChanged();
                    }
                }
            }
            private global::System.String _Reference;
            partial void OnReferenceChanging(global::System.String value);
            partial void OnReferenceChanged();
    
            #endregion
        
        }
    I also tried removing [DataContractAttribute] and replacing it with [DataContract] only. But still the same error. Please suggest.


    Don't miss to 'Vote As Helpful' or 'Mark As Answer' a deserving post.

    Tuesday, December 18, 2012 1:54 PM
  • Hi,

    FYI

    http://social.msdn.microsoft.com/Forums/en/wcf/thread/d36875b2-abf7-4162-9d3b-39bea79a9850 

    Also below is the link to standard guidelines:

    http://msdn.microsoft.com/en-us/library/bb552364.aspx

    Regards.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help , or you may vote-up a helpful post



    • Edited by murtazagandhi Tuesday, December 18, 2012 3:05 PM edit
    • Proposed as answer by murtazagandhi Tuesday, December 18, 2012 3:05 PM
    • Marked as answer by Md.Ibrahim Wednesday, December 19, 2012 9:24 AM
    Tuesday, December 18, 2012 3:03 PM
  • Thanks for your assistance.

    I didn't think WcfTestClient would do such a lousy job.

     

    Don't miss to 'Vote As Helpful' or 'Mark As Answer' a deserving post.

    Wednesday, December 19, 2012 9:26 AM
  • Hi

    Mr. Md.Ibrahim,

    Here the framework is not the issue,

    the values you enter for testing or the way the code has been written also may

    be of significance.

    In the above link it says support is not available for EF,

    while I saw this link

    http://www.codeproject.com/Articles/127395/Implementing-a-WCF-Service-with-Entity-Framework

    with code

     public Product GetProduct(int id)
            {
                NorthwindEntities context = new NorthwindEntities();
                var productEntity = (from p
                                     in context.ProductEntities
                                     where p.ProductID == id
                                     select p).FirstOrDefault();
               if (productEntity != null)
                   return TranslateProductEntityToProduct(productEntity);
               else
                   throw new Exception("Invalid product id");
            }
    Here exception handling is done for null and FirstOrDefault() is use alongwith the criteria for match ,that is the id

    Regards.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help , or you may vote-up a helpful post


    • Edited by murtazagandhi Wednesday, December 19, 2012 9:49 AM edit
    Wednesday, December 19, 2012 9:48 AM