Can I have an optional parameter for an ASP.NET SOAP web service

后端 未结 6 2036
[愿得一人]
[愿得一人] 2020-11-29 12:30

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 Hell         


        
6条回答
  •  清酒与你
    2020-11-29 12:54

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

    Look at http://msdn.microsoft.com/en-us/library/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;
    }
    

    The methods will be made visible as Add2 and Add3to the outside.

提交回复
热议问题