我可以有一个ASP.NET SOAP网络服务的可选参数 [英] Can I have an optional parameter for an ASP.NET SOAP web service

查看:284
本文介绍了我可以有一个ASP.NET SOAP网络服务的可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立与此签名,如果参数2为空不抛出异常的Web服务。这可能吗?

I want to build a webservice with this signature, which does not throw an exception if param2 is left empty. Is this possible?

[WebMethod]
public string HelloWorld(string param1, bool param2) { }

唯一的例外是试图转换为Boolean空字符串时引发一个System.ArgumentException。

The exception is a System.ArgumentException that is thrown when trying to convert the empty string to boolean.

这是没有工作至今思路:

Ideas that have not worked so far:

  • 方法重载是不允许的web服务,比如

  • method overloading is not allowed for webservices, like

public string HelloWorld(string param1)
{
    return HelloWorld(param1, false);
}

作为建议<一href="http://stackoverflow.com/questions/1155826/best-way-of-making-an-argument-optional-for-a-c-webmethod">here:

  • 布尔可空布尔?。同样的异常。
  • 操纵WSDL,请参见这个答案
  • make bool nullable bool?. Same exception.
  • manipulate the WSDL, see this answer

我的问题是有关这个问题,但唯一的答案要点WCF的合同,我还没用过。

My question is related to this question, but the only answer points to WCF contracts, which I have not used yet.

推荐答案

您可以有一个重载的方法的web服务与MessageName属性。这是一种解决方法,实现了重载功能。

You can have a Overloaded Method in webservices with MessageName attribute. This is a workaround to achieve the overloading functionality.

http://msdn.microsoft。 COM / EN-US /库/ byxd99hx%28VS.71%29.aspx

[WebMethod(MessageName="Add3")]
public double Add(double dValueOne, double dValueTwo, double dValueThree)
{
   return dValueOne + dValueTwo + dValueThree;
}

[WebMethod(MessageName="Add2")]
public int Add(double dValueOne, double dValueTwo)
{
   return dValueOne + dValueTwo;
}

该方法将变为可见作为 ADD2 ADD3 到外面。

这篇关于我可以有一个ASP.NET SOAP网络服务的可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆