使用c#client中的复杂参数调用webservice

时间:2012-01-26 19:57:19

标签: webservices-client

您好,这是一个班级......

公共课认证     {

    private string userField;
    private string passwordField;
    public string user
    {
        get
        {
            return this.userField;
        }
        set
        {
            this.userField = value;
        }
    }

    public string password
    {
        get
        {
            return this.passwordField;
        }
        set
        {
            this.passwordField = value;
        }
    }

}

此处是网络服务:

[WebMethod]
public Vehicle[] getVehiculeList(Authentification authentification)
{
....
}

这里是客户端和webservice的调用: (与Web服务中的相同类Authentification已定义)

Authentification azz = new Authentification() ;
azz.user = "toto";
azz.password = "tata";
string aa = ws.getVehiculeList(azz);

给出错误: 错误27“WSCL.localhost.Service1.getVehiculeList(WSCL.localhost.Authentification)”的最佳重载方法匹配具有一些无效参数

错误28参数'1':无法从'WSCL.Authentification'转换为'WSCL.localhost.Authentification'

有任何帮助吗?

非常感谢!

1 个答案:

答案 0 :(得分:1)

可能发生的是您在客户端上引用了包含数据实体的程序集(例如,身份验证),现在您同时拥有代理实体(WSCL.localhost.Authentification)和原始服务器实体({{1 }})。如果您更改客户端使用身份验证以使用代理类(WSCL.Authentification),它应该可以工作。

如果切换到WCF,您将能够将身份验证等数据实体移动到单独的程序集中,然后在您的服务和客户端之间共享此类型。 AFAIK这在ASMX中无法“开箱即用”。

相关问题