MZH
MZH

Reputation: 1534

Use EF entity classes in WCF

I'm creating an app based on SOA, I've created WCF Service Project using Framework 4.0, in that I'm using Entity framework, in WCF operation Contract method I'm using the class generated by the EF, but the WCF can't recognize these objects, when I checked those classes in designer mode, they are like

[EdmEntityTypeAttribute(NamespaceName="quizTestDBModel", Name="tbl_adminUser")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class tbl_adminUser : EntityObject
    {
        #region Factory Method

    /// <summary>
    /// Create a new tbl_adminUser object.
    /// </summary>
    /// <param name="adminUserId">Initial value of the adminUserId property.</param>
    public static tbl_adminUser Createtbl_adminUser(global::System.Int32 adminUserId, global::System.String name, global::System.String userid, global::System.String password)
    {
        tbl_adminUser tbl_adminUser = new tbl_adminUser();
        tbl_adminUser.adminUserId = adminUserId;
        return tbl_adminUser;
    }

    #endregion
    #region Primitive Properties

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Int32 adminUserId
    {
        get
        {
            return _adminUserId;
        }
        set
        {
            if (_adminUserId != value)
            {
                OnadminUserIdChanging(value);
                ReportPropertyChanging("adminUserId");
                _adminUserId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("adminUserId");
                OnadminUserIdChanged();
            }
        }
    }
    private global::System.Int32 _adminUserId;
    partial void OnadminUserIdChanging(global::System.Int32 value);
    partial void OnadminUserIdChanged();

    #endregion

}

When I use this class in my operation contract as

 int adminRegister(tbl_adminUser _adminUser);

It give error on that method, "The operation is not supported in WCF Test Client, because it uses type tbl_adminUser"

Thanks

Upvotes: 0

Views: 940

Answers (2)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364399

The error just says that WCF Test client doesn't support your contract but it doesn't mean that WCF itself doesn't. WCF Test client is for testing the most common scenarios and it doesn't support all WCF features. Write test application or use more powerful test tool like SoapUI to validate that your service works.

Also follow @John's advices because your current design has awful naming convention, it exposes EntityObject based entities and it is far from SOA. By your description it is simple CRUD exposed as a service. You will achieve similar result with WCD Data Services much faster.

Upvotes: 1

John Saunders
John Saunders

Reputation: 161831

If you are passing platform-specific data across a service boundary, then you are not using SOA.

Entity Framework classes are specific to .NET and to Entity Framework. Do not pass them across a service boundary.

I also note that you want to subject your clients to your naming conventions (tbl_adminUser), as well as the fact that there are tables involved. Why do the callers of your service need to know anything about the fact that you've implemented the concept of an "admin user" by using a table named tbl_adminUser?

You should create yourself a Data Transfer Object class named, for instance, AdminUser. It should have properties for all of the interesting public aspects of an admin user (apparently, just AdminUserId). It should have no behavior at all - just data.

This is the class that should be sent by and received from your service.

And, yes, you'll have to implement mapping code.

Upvotes: 4

Related Questions