简体   繁体   中英

WCF operation contract with params array parameter

I think this guy has the same problem as me, but I need clarification:

wcf service with params

Anyway, I'm trying to write a WCF operation contract that takes in a string the same way as String.Format does using a params array of objects, and a formatting string. That way, I can call the operation like this:

OperationContractMethod("Hello {0}", "Dave");

Instead of doing it like this:

OperationContractMethod(String.Format("Hello {0}", "Dave"));

Basically, the operation contract method takes a string, but I just want to be able to pass the string in formatted form for convenience. It works well with normal methods, because I can just create the function explicitly, but WCF presents the challenge that I have to write this in interface form first. The other guy said something about not all objects being serializable. Is it possible to do this or not?

No, I don't think it is possible. The data contract needs to be specific, and attributed, eg

[DataContract]
public class Contact
{
    [DataMember]
    public string Name { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM