Methods with Nullable Types not working in ASMX Web Service using GET

℡╲_俬逩灬. 提交于 2019-12-22 05:41:35

问题


I have an ASMX Web Service set up to use the HTTP GET method. Simple methods which take basic String and Int parameters are working ok, and I can call MyService.asmx/MethodName?Param=Value and get a response back in XML.

However, when I have a method which has a nullable Int (i.e. int?), I get this error:

< Method Name > Web Service method name is not valid.

The error message is confusing, as the method does exist, just not in the GET scope. I presume this is because a nullable type is too complex to be passed via the URL, but I can't find any documentation or SO posts on this.

I appreciate that complex types like Lists or custom classes etc will not work using GET, but I would have assumed that a simple nullable int or nullable datetime could be handled natively, simply by detecting whether it was omitted from the URL. Guess it's not that simple!

Any advice or workarounds would be greatly appreciated.

Thanks, Tim


回答1:


nullable int is not too complex. it should produce

  <s:element minOccurs="1" maxOccurs="1" name="Param" nillable="true" type="s:int" /> 

in WSDL. Check out this post. The error could be for something else, perhaps?




回答2:


You must use json text if you have such int? argument because it is an object type not primitive type. The error is misleading because the service exists.

if you have int? a as parameter you must send "{'a':null}" as content to server or some integer instead of null.



来源:https://stackoverflow.com/questions/5301549/methods-with-nullable-types-not-working-in-asmx-web-service-using-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!