web服务中的方法重载

本文关键字:方法 重载 服务 web | 更新日期: 2023-09-27 17:50:33

我有两个关于web服务的问题。

    如何在web服务中实现方法重载。
  1. 如何在web服务中实现安全(认证)。

web服务中的方法重载

如何在web服务中实现方法重载

如果您使用的是SOAP,则不能。方法名在导出的WSDL中必须具有惟一的名称。根据所使用的技术,有不同的方法来指定方法名。例如,在WCF中,您可以使用[OperationContract]属性来指定名称:

[ServiceContract]
public interface IMyService
{
    [OperationContract(Name = "Foo")]
    void Foo();
    [OperationContract(Name = "FooWithId")]
    void Foo(int id);
}

如何在web服务中实现安全(认证)。

下面的指南是在WCF中实现安全性的一个很好的开始。

允许重载:

[WebMethod(MessageName = "MaxInt", Description = "Compare two int values 
and return the max value", EnableSession = true)]
public int MaxValue(int a, int b)
{
   return (a > b ? a : b);
}
[WebMethod(MessageName = "MaxFloat", Description = "Compare two float values 
and return the max value", EnableSession = true)]
public float MaxValue(float a, float b)
{
   return (a > b ? a : b);
}

你所说的认证到底是什么意思?显然,您可以使用验证密钥来访问web服务。这个问题令人困惑。请阐述。