piatok 8. júna 2012

WCF : Cannot have two operations in the same contract with the same name

WCF - over HTTP  (and also Web Services in generaly) does not allow method overloading (it means :same method name but different atributes types, which is in C# absolutely correct).


Reason:
When data is passed to an XML Web service it is sent in a request and when it is returned it is sent in a response. Therefore, if an XML Web service contains two or more XML Web service methods with the same name, no uniquely identification will be there. Hence it will produce error.

You should use OperationContract atribute "name" or simply rename one of the methods.



 
This is example from my current project (in Slovak language)
Code Snippet
  1.         [OperationContract]
  2.         APIVytvorDokumentResponse VytvorDokument(global::eDocsInterfaceCUD.CBO_API.CUD.MTOM.APIVytvorDokumentByteArrayRequest request);
  3.        
            [OperationContract(Name = "VytvorDokumentCezStream")]
  4.         APIVytvorDokumentResponse VytvorDokument(global::eDocsInterfaceCUD.CBO_API.CUD.MTOM.APIVytvorDokumentStreamRequest request);

Žiadne komentáre:

Zverejnenie komentára