Hallo allemaal,
Ik heb een interface waarin mijn functies gedeclareert zijn. Een aantal overloaden elkaar en hebben dus dezelfde naam. WCF kan hiermee niet overweg en er wordt gezegd dat ik de Name property binnen de OperationalContractAttribute moet veranderen om de naamgeving van die functie te veranderen. Dit heb ik ook toegepast. Toch krijg ik een exception. De code is hieronder weergegeven. De bijbehorende exception is helemaal onderaan weergegeven. Iemand een idee waar het precies fout gaat? Alvast bedankt.
De ISynopServiceContract Interface:
De SynopService Class:
De Exception
Ik heb een interface waarin mijn functies gedeclareert zijn. Een aantal overloaden elkaar en hebben dus dezelfde naam. WCF kan hiermee niet overweg en er wordt gezegd dat ik de Name property binnen de OperationalContractAttribute moet veranderen om de naamgeving van die functie te veranderen. Dit heb ik ook toegepast. Toch krijg ik een exception. De code is hieronder weergegeven. De bijbehorende exception is helemaal onderaan weergegeven. Iemand een idee waar het precies fout gaat? Alvast bedankt.
De ISynopServiceContract Interface:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| Imports System.ServiceModel
Public Interface ISynopServiceContract
<OperationContractAttribute(Name:="GetDataByYear")> _
Function GetData(ByVal varName As String, ByVal year As Integer) As Synop
<OperationContractAttribute(Name:="GetDataByYearMonth")> _
Function GetData(ByVal varName As String, ByVal year As Integer, ByVal month As Integer) As Synop
<OperationContractAttribute(Name:="GetDataByDateRange")> _
Function GetData(ByVal varName As String, ByVal startDateTime As DateTime, ByVal endDateTime As DateTime) As Synop
<OperationContractAttribute(Name:="ExistsOfYear")> _
Function ExistsSynop(ByVal varName As String, ByVal year As Integer) As Boolean
<OperationContractAttribute(Name:="ExistsOfYearMonth")> _
Function ExistsSynop(ByVal varName As String, ByVal year As Integer, ByVal month As Integer) As Boolean
' Not a operational contract.
Function Save(ByVal data As Synop) As Boolean
End Interface |
De SynopService Class:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| Imports System.ServiceModel
Public Class SynopService
Implements ISynopServiceContract
Private mManager As SynopManager
Public Sub New()
Try
mManager = New SynopManager()
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Sub
Public Function ExistsSynop(ByVal varName As String, ByVal year As Integer) As Boolean Implements ISynopServiceContract.ExistsSynop
Return mManager.ExistsSynop(varName, year)
End Function
Public Function ExistsSynop(ByVal varName As String, ByVal year As Integer, ByVal month As Integer) As Boolean Implements ISynopServiceContract.ExistsSynop
Return mManager.ExistsSynop(varName, year, month)
End Function
Public Function GetData(ByVal varName As String, ByVal startDateTime As Date, ByVal endDateTime As Date) As Synop Implements ISynopServiceContract.GetData
Return mManager.GetData(varName, startDateTime, endDateTime)
End Function
Public Function GetData(ByVal varName As String, ByVal year As Integer) As Synop Implements ISynopServiceContract.GetData
Return mManager.GetData(varName, year)
End Function
Public Function GetData(ByVal varName As String, ByVal year As Integer, ByVal month As Integer) As Synop Implements ISynopServiceContract.GetData
Return mManager.GetData(varName, year, month)
End Function
Public Function Save(ByVal data As Synop) As Boolean Implements ISynopServiceContract.Save
Return mManager.Save(data)
End Function
End Class |
De Exception
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| [InvalidOperationException: Cannot have two operations in the same contract with the same name, methods GetData and GetData in type ServiceContracts.ISynopServiceContract 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.] System.ServiceModel.Description.TypeLoader.CreateOperationDescription(ContractDescription contractDescription, MethodInfo methodInfo, MessageDirection direction, ContractReflectionInfo reflectionInfo, ContractDescription declaringContract) +3287 System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction) +177 System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo& reflectionInfo, Object serviceImplementation) +1038 System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation) +204 System.ServiceModel.Description.ContractDescription.GetContract(Type contractType, Type serviceType) +53 System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) +470 System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +145 System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +258 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +29 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +307 System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +702 System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +32 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +430 [ServiceActivationException: The service '/Synop/SynopService.svc' cannot be activated due to an exception during compilation. The exception message is: Cannot have two operations in the same contract with the same name, methods GetData and GetData in type ServiceContracts.ISynopServiceContract 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..] System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +909 System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath) +356 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest() +234 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() +727 System.ServiceModel.Activation.HostedHttpModuleRequestAsyncResult.BeginRequest() +141 System.ServiceModel.Activation.HttpModule.StartBeginProcessRequest(Object sender, EventArgs e, AsyncCallback cb, Object extraData) +68 System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +148 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +138 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +65 |