WCF를 사용하여 채팅 서비스를 빌드했습니다. 나는 datacontract 속성모든 datacontract 클래스 생성 방법
[DataContract]
public class Message
{
string _sender;
string _content;
DateTime _time;
[DataMember(IsRequired=true)]
public string Sender
{
get { return _sender; }
set {
_sender = value;
}
}
[DataMember(IsRequired = true)]
public string Content
{
get { return _content; }
set {
_content = value;
}
}
[DataMember(IsRequired = true)]
public DateTime Time
{
get { return _time; }
set {
_time = value;
}
}
}
로 표시된 클래스가 그리고 내가으로 VisualStudio 2010에서 클라이언트 코드를 생성 할 때
[ServiceContract(Namespace="", SessionMode = SessionMode.Required, CallbackContract = typeof(IChatCallback))]
public interface IChat
{
[OperationContract]
bool Connect(Client client);
[OperationContract(IsOneWay=true, IsInitiating=false, IsTerminating=true)]
void Disconnect();
[OperationContract(IsOneWay = true, IsInitiating = false)]
void Whisper(string target, string message);
}
아래 수준의 메시지가 생성되지 않습니다처럼 내 서비스 계약이다. 그러나 그것은 "메시지"문자열에 대한 서비스 계약에서 "속삭임"메서드의 매개 변수 "메시지"유형을 변경할 때 생성됩니다.
나는 "메시지"없습니다 "문자열"을 매개 변수 메시지의 유형을 변경 :
[OperationContract(IsOneWay = true, IsInitiating = false)]
void Whisper(string target, Message message);
나는 메시지 클래스를 필요로 콜백 클래스는 제대로 작동했습니다.
public interface IChatCallback
{
void RefreshClient(List<Client> clients);
void ReceiveWhisper(Message message);
void ReceiveNotifyClientConnect(Client joinedClient);
void ReceiveNotifyClientDisconnect(Client leaver);
}
그리고 질문은 왜이 서비스 계약의 방법 매개 변수 또는 반환 값에 포함되지 않은 경우 datacontract 속성이 발생하지 않는 것으로 표시 클래스입니다.
아 내가 수동으로 – brian
그것을 생성해야합니다 참조 나는 콜백 클래스는 클래스 "메시지"를 필요로 "IChatCallback는"일 당신은 인터페이스 내가 그 안에 무엇을 볼 수 있다는 게시하지 않은 제대로 – brian
해야 ...! –