以与本地类库相同的方式使用WCF服务

时间:2016-04-13 11:35:59

标签: c# wcf

我希望以与本地类库相同的方式使用WCF服务。

例如:

// SystemLogin oLogin = new SystemLogin();                                    // create object instance from class library
ServiceReference1.SystemLogin oLogin = new ServiceReference1.SystemLogin();   // create object instance from WCF-service
oLogin.Login = "Login";                                                       // set property No. 1
oLogin.Password = "Password";                                                 // set property No. 2
oLogin.Connect();                                                             // call method

有可能吗?如果是,WCF合同将如何?

1 个答案:

答案 0 :(得分:0)

换句话说我的问题。我有一个简单的类库(2个属性,1个方法),并想在WCF服务上使用它,几乎没有改变我的Win-app功能:

  

//从WCF-service

创建对象实例      

ServiceReference1.SystemLogin oLogin = new   ServiceReference1.SystemLogin();

     

//而不是

     

//从类库中创建对象实例

     

SystemLogin oLogin = new SystemLogin();

WCF合约将如何?

类库示例:

class SystemLogin
{

    private string login;
    private string password;

    public SystemLogin()
    {
        this.login = "";
        this.password = "";
    }

    public int Connect()
    {
        return 1;
    }

    public string Login
    {
        get { return login; }
        set { login = value; }
    }

    public string Password
    {
        get { return password; }
        set { password = value; }
    }