0

我正在设计一个具有重载方法的 Web 服务,有人说我们应该尽量不要在 Web 服务中重载方法,因为生成 wsdl 或非 .net 服务尝试使用这些方法时可能会出现问题。

我通过创建一个简单的服务来测试生成 wsdl 的场景,该服务具有两个添加方法,一个采用整数,另一个采用双精度,没有任何问题。

所以想检查一下 1. 如果我在 wsdl 中遗漏了一些我忽略的东西。2. 非.net webservice cosuming 服务是否存在功能过载的已知问题。3.如果可以的话,不建议使用重载函数吗?

以下是我的测试服务的样子 --service 库

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace EvalServiceLibrary
{
     [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class EvalService: IEvalService
    {

        public int AddEval(int a, int b, int c)
        {
            return a + b + c;
        }

        public double AddEval(double a, double b, double c)
        {
            return a + b + c;
        }
    }
}

--界面代码是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace EvalServiceLibrary
{
    [ServiceContract]
    public interface IEvalService
    {
        [OperationContract(Name = "Addint")]
        int AddEval(int a, int b, int c);
        [OperationContract(Name = "Addfloat")]
        double AddEval(double a, double b, double c);

    }
}

--服务代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace EvalServiceLibrary
{
     [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class EvalService: IEvalService
    {

        public int AddEval(int a, int b, int c)
        {
            return a + b + c;
        }

        public double AddEval(double a, double b, double c)
        {
            return a + b + c;
        }
    }
}
4

1 回答 1

1

您不会有问题,因为 OperationContract 对每个操作都有不同的名称(这是重要的名称)。WSDL 使用者不会知道您使用重载来实现。您还可以打开 WSDL 并查看这是两个不同的操作。

于 2013-09-05T22:57:39.200 回答