Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to add an attribute to a method declared on partial interface?

Ihave this code on a file
C#
using System;
using System.Net.Security;
using WCF = global::System.ServiceModel;

namespace CMAWCF.ServiceContracts
{
    public partial interface IMyServiceServiceContract
    {
        [WCF::TransactionFlow(WCF::TransactionFlowOption.Mandatory)]
        void DoSomething(CMAWCF.MessageContracts.RequestDoSomething
                             request);
    }
}


and this code was generated by a tool on other file on the same project
C#
using System;
using System.Net.Security;
using WCF = global::System.ServiceModel;

namespace CMAWCF.ServiceContracts
{
    public partial interface IMyServiceServiceContract
    {
        //... More methods
        [WCF::FaultContract(typeof(CMAWCF.FaultContracts.DefaultFaultContract))]
	[WCF::OperationContract(IsTerminating = false, IsInitiating =
        true, IsOneWay = false, AsyncPattern = false, Action = "DoSomething",
        ProtectionLevel = ProtectionLevel.None)]
        void DoSomething(CMAWCF.MessageContracts.RequestDoSomething
                             request);
        //... More methods
    }
}


But I got an error:

Type 'CMAWCF.ServiceContracts.IMyServiceServiceContract' already defines a member called 'DoSomething' with the same parameter types

How can I get an output like this:

C#
using System;
using System.Net.Security;
using WCF = global::System.ServiceModel;

namespace CMAWCF.ServiceContracts
{
    public partial interface IMyServiceServiceContract
    {
        [WCF::TransactionFlow(WCF::TransactionFlowOption.Mandatory)]
        [WCF::FaultContract(typeof(CMAWCF.FaultContracts.DefaultFaultContract))]
	[WCF::OperationContract(IsTerminating = false, IsInitiating =
        true, IsOneWay = false, AsyncPattern = false, Action = "DoSomething",
        ProtectionLevel = ProtectionLevel.None)]
        void DoSomething(CMAWCF.MessageContracts.RequestDoSomething
                             request);
    }
}


I found some discussion about it, but nothing solid. Any idea? thanks in advance.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Oct-12 21:01pm    
And why did you write DoSomething twice?! What tool? If this is your tool, write it correctly, that's it.
--SA
YORENGOY 8-Oct-12 22:34pm    
I´m using Web Service Software Factory 2010 and I want to implement transactions,so I need to add the attribute [WCF::TransactionFlow(WCF::TransactionFlowOption.Mandatory)]; If this attribute is added to the service contract each time the code is generated, the changes will be loss

1 solution

This problem has nothing to do with attributes or… it does not have to do with anything. Partial syntax is not very much of syntax; it's something very simple, used to define some type in two or more fragments of text of the code, typically in different files. And nothing else. It does not allow you to repeat any declaration. Your method should be declared only once, with the attribute. If this is your tool, fix it. If not, do not use it, or, in worst case, around by using it only where it works correctly.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900