First, let’s create a simple service contract with 2 overloaded function, something like the following,
Public Interface IService1
Function GetData(ByVal intParam As Integer) As String
Function GetData(ByVal intParam As Integer, ByVal strParam As String) As String
End Interface
Server Error in '/FundTransferService' Application.
Cannot have two operations in the same contract with the same name, methods GetData and GetData in type IService1 violate this rule. You can change the name of one of the operations by changing the method name or by using the Name property of OperationContractAttribute.
We will add a “Name” property to the “OperationContract” attribute with different value,like the following.
Public Interface IService1
Function GetData(ByVal intParam As Integer) As String
Function GetData(ByVal intParam As Integer, ByVal strParam As String) As String
End Interface
Dim resultInt As String = sev1.GetDataInt(5)
Dim resultString As String = sev1.GetDataString(5, "Five")
sev1.Close()
We will need to modify the client proxy class as well to fully implent the function overloading .
At the client side in the Reference.vb file, we have to add the same “Name” property to that OperationContract attribute in the Interface “IService1” and change the 2 method name to “GetData”.See below,
System.ServiceModel.ServiceContractAttribute(ConfigurationName:="Service1.IService1")>
Public Interface IService1
Function GetData(ByVal intParam As Integer) As String
End Interface
Now we will change the implimentation of that interface to make the 2 method of same method name. It is in the same Reference.VB class.
public Function GetData(ByVal intParam As Integer) As String Implements Service1.IService1.GetData
Return MyBase.Channel.GetData(intParam)
End Function
Public Function GetData(ByVal intParam As Integer, ByVal strParam As String) As String Implements Service1.IService1.GetData
Return MyBase.Channel.GetData(intParam, strParam)
End Function
Dim resultInt As String = sev1.GetData(5)
Dim resultString As String = sev1.GetData(5, "Five")
sev1.Close()