Wcf Service Library not working with ServicedComponent

0

The UserComponent doesn't work with WCF Service Library. UserComponent works in a Console Application.

I get the error when I run component in WCF Service Library:

 System.Runtime.InteropServices.COMException: 'Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))'

Now I have done a bit google search and they say that I need to make it a x86 platform target. But it doesn't work when I change it to x86 platform target. And the Prefer 32-bit checkbox is disabled in service library Properties.

 [ServiceContract]
    public interface IUser
    {
        [OperationContract]
        bool InsertUser(string username, string firstName, string lastName);

        [OperationContract]
        List<UserData> GetUsers();
    }


 public class User : IUser
    {
        public List<UserData> GetUsers()
        {
            UserComponent userComponent = new UserComponent();
            List<UserData> userDatas = new List<UserData>();
            List<QuoteEntities.User> users = userComponent.GetUsers();
            foreach (var user in users)
            {
                UserData userData = new UserData();
                userData.Firstname = user.FirstName;
                userData.ID = user.Id;
                userData.Lastname = user.LastName;
                userData.Username = user.UserName;
                userDatas.Add(userData);
            }
            return userDatas;
        }

        public bool InsertUser(string username, string firstName, string lastName)
        {
            UserComponent userComponent = new UserComponent();
            return userComponent.InsertUser(username, firstName, lastName);
        }
    }

 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface MyQuoteAppComponentIUser
    {
        bool InsertUser(string username, string firstName, string lastName);
        List<QuoteEntities.User> GetUsers();
    }


    [Synchronization(SynchronizationOption.RequiresNew)]
    [EventTrackingEnabled]    
    [Transaction(TransactionOption.RequiresNew)]
    [JustInTimeActivation]
    public class UserComponent : ServicedComponent, MyQuoteAppComponentIUser
    {
        public Guid GetActivityId()
        {
            return ContextUtil.ActivityId;
        }

        public List<QuoteEntities.User> GetUsers()
        {
            UserDataAccess userDataAccess = new UserDataAccess();
            List<QuoteAppDAL.User> users = userDataAccess.GetUsers();
            List<QuoteEntities.User> usersToReturn = new List<QuoteEntities.User>();
            foreach (var user in users)
            {
                QuoteEntities.User user2 = new QuoteEntities.User();
                user2.FirstName = user.FirstName;
                user2.Id = user.Id;
                user2.LastName = user.LastName;
                user2.UserName = user.UserName;
                usersToReturn.Add(user2);
            }
            return usersToReturn;
        }

        public bool InsertUser(string username, string firstName, string lastName)
        {
            UserDataAccess userDataAccess = new UserDataAccess();
            return userDataAccess.InsertUser(username, firstName, lastName);
        }
    }
wcf
servicedcomponent
asked on Stack Overflow Oct 19, 2018 by sly_Chandan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0