简体   繁体   English

如何将可选参数发送到c#中的“webservice”?

[英]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 : 我通过jquery ajax调用此Web服务:

$.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. 我只想一次用p1调用FetchBox,以后再用p2而不是p1等等。

in many situations i need to call FetchBox method with any of p1 or p2 or p3 or ... parameter. 在许多情况下,我需要使用p1或p2或p3或...参数中的任何一个调用FetchBox方法。 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. c#4中的可选参数不适用于Web服务。

also params string[] parameters is not suitable here because i need to know the parameter name. 另外params string []参数在这里不合适,因为我需要知道参数名称。

You cannot send optional parameters to a SOAP web service. 您无法将可选参数发送到SOAP Web服务。 The SOAP protocol has no concept of optional parameters. SOAP协议没有可选参数的概念。

Also, you should not be using ASMX services at all. 此外,您根本不应该使用ASMX服务。 That's a legacy technology that shouldn't be used for new development. 这是一项不应用于新开发的传统技术。 WCF should be used instead. 应该使用WCF代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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