您可以将变量声明为Nullable (of <your type>),并且只需一个包含所有 10 个参数的 Web 服务
这是您的 Web 方法,只有 2 个可选参数,但您可以轻松地将其扩展到 10 个:
<WebMethod(Description:="TEST1")> _
Public Function TEST1(<XmlElement()> param1 As Nullable(Of Double), <XmlElement()> param2 As Nullable(Of Double)) As <XmlElement()> Double
Try
Dim result As Double = 0
If Not param1 Is Nothing Then
result += param1
End If
If Not param2 Is Nothing Then
result += param2
End If
Return result
Catch ex As Exception
End Try
Return 0
End Function
这个 SoapUI 调用:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://mysite.org/">
<soapenv:Header/>
<soapenv:Body>
<not:TEST1>
<not:param1>1</not:param1>
<not:param2>2</not:param2>
</not:TEST1>
</soapenv:Body>
</soapenv:Envelope>
结果如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<TEST1Response xmlns="http://mysite.org/">
<TEST1Result>3</TEST1Result>
</TEST1Response>
</soap:Body>
</soap:Envelope>
这个 SoapUI 调用:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://mysite.org/">
<soapenv:Header/>
<soapenv:Body>
<not:TEST1>
<not:param1>1</not:param1>
</not:TEST1>
</soapenv:Body>
</soapenv:Envelope>
结果如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<TEST1Response xmlns="http://mysite.org/">
<TEST1Result>1</TEST1Result>
</TEST1Response>
</soap:Body>
</soap:Envelope>
Nullable (of Double) 在这个例子中两个参数都是可选的。