从C#客户端调用具有复杂参数的Web服务

发布于 2024-12-29 05:20:48 字数 1103 浏览 1 评论 0原文

你好,这是一个类...

公共类身份验证 {

    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;
        }
    }

}

这里是 Web 服务:

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

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

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”。身份验证

有帮助吗?

非常感谢!

Hello, Here is a class ...

public class Authentification
{

    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;
        }
    }

}

here the web service :

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

Here the client and the call of webservice :
(the same class Authentification like in the webservice has been defined)

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

gives an error :
Error 27 The best overloaded method match for 'WSCL.localhost.Service1.getVehiculeList(WSCL.localhost.Authentification)' has some invalid arguments

and

Error 28 Argument '1': cannot convert from 'WSCL.Authentification' to 'WSCL.localhost.Authentification'

Any help ?

Thank a lot !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦毁影碎の 2025-01-05 05:20:48

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

如果切换到 WCF,您将能够将身份验证等数据实体移动到单独的程序集中,然后在服务和客户端之间共享相同的类型。据我所知,这在 ASMX。

What might have happened is that you have referenced the assembly containing the data entities (e.g. Authentication) on your client, and now you have both the proxied entity (WSCL.localhost.Authentification) and the original server entity (WSCL.Authentification). If you change your client's use of Authentication to use the proxied class (WSCL.localhost.Authentification) it should work.

If you switch to WCF, you will be able to move the data entities like Authentication into a separate assembly, and then Share this same type between your Service and your Client. AFAIK this isn't possible 'out of the box' in ASMX.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文