简体   繁体   中英

how to send optional parameters to a “webservice” in c#?

i have a web service with signature :

[WebMethod(EnableSession = true)]
public Box FetchBox(string boxId, string p1, string p2, string p3 )

i call this web service by a jquery ajax :

$.ajax({
  url: "/WS/Ajaxify.asmx/FetchBox",
  data: "{ 'boxId': '" + boxId + "' }",
  dataType: "json",
  type: "POST",
  contentType: "application/json; charset=utf-8"
});

i want to call FetchBox one time only with p1, later with p2 but not p1 and so on.

in many situations i need to call FetchBox method with any of p1 or p2 or p3 or ... parameter. i dont like to send all parameters because the system is plugin based and plugins do not know about others parameters.

optional parameter in c#4 does not working for a web service.

also params string[] parameters is not suitable here because i need to know the parameter name.

You cannot send optional parameters to a SOAP web service. The SOAP protocol has no concept of optional parameters.

Also, you should not be using ASMX services at all. That's a legacy technology that shouldn't be used for new development. WCF should be used instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM