请问服务契约ServiceContract中可不可以有属性? [ServiceContract]
public interface IWCFService
{
//操作契约
[OperationContract]
string SayHello(string name);
[DataMember]
int[,] Name
{
get;
set;
}
}为什么我这么写在Add service之后看不到呢?
public interface IWCFService
{
//操作契约
[OperationContract]
string SayHello(string name);
[DataMember]
int[,] Name
{
get;
set;
}
}为什么我这么写在Add service之后看不到呢?
namespace Microsoft.WCF.Documentation
{
[ServiceContract(
Namespace="http://microsoft.wcf.documentation",
Name="SampleService",
ProtectionLevel=ProtectionLevel.EncryptAndSign
)]
public interface ISampleService{
[OperationContract]
string SampleMethod(string msg);
} class SampleService : ISampleService
{
#region ISampleService Members public string SampleMethod(string msg)
{
return "The service greets you: " + msg;
} #endregion
}
}
你必须明白一点,自定义的属性必须在类中,一个可序列化的类或者一个标识了[DataContract]的类,而不能放在接口中。否则,那些属性将不传递,只有服务端可用。
也就是说服务契约只能是方法
而数据契约只能是数据那么数据契约可以定义operationcontact吗?