Can a WCF service contract have a nullable input parameter?

前端 未结 4 1567
-上瘾入骨i
-上瘾入骨i 2021-02-03 10:13

I have a contract defined like this:

[OperationContract]
[WebGet(UriTemplate = \"/GetX?myStr={myStr}&myX={myX}\", BodyStyle = WebMessageBodyStyle.Wrapped)]
s         


        
4条回答
  •  长情又很酷
    2021-02-03 10:46

    Yes, you can have nullable parameters with WCF. I think your problem here is that QueryStringConverter does not work with nullable parameters.

    What to do? Do you need to use the UriTemplate attribute? If you published this as a 'classic web service' then you wouldn't have this issue.

    The other option is to follow the advise in the link you provided - i.e. receive the myX parameter as string and then cast it to an int?, where (say) "n" is null. Not pretty.

提交回复
热议问题