WCF方法不接受nullable int参数的空值

时间:2012-11-24 03:31:01

标签: c# asp.net wcf int nullable

我有一个WCF方法,可以使用可空int作为参数进行编译。但是,当我从另一个项目引用该服务时,它期望一个普通的int作为参数。通过阅读其他stackoverflow线程,似乎可以有一个可以为null的int参数,但是,我无法弄清楚如何实现它。

我的代码如下:

[ServiceContract]
public interface IService
{
    [OperationContract]
    string CompletePayment(int paymentType, int? userId)
}


public class Service : IService
{

    public string CompletePayment(int paymentType, int? userId)
    {
        return "it worked";
    }        
}         

1 个答案:

答案 0 :(得分:1)

int?只是Nullable<int>的语法糖,我认为在服务合同中使用泛型时存在一些限制。请参阅此答案:Can a WCF service contract have a nullable input parameter?

相关问题