2010-02-17 7 views
2

좋은 하루 사람. 나는 이전에 이런 유형의 사이트에 게시 한 적이 없지만 그것이 어떻게 진행되는지 볼 수 있습니다.WCF 서비스 클라이언트

오늘 저는 처음으로 WCF로 작업하기 시작했습니다. 몇 가지 스크린 캐스트를 보았고 이제는 구현 한 첫 번째 솔루션으로 이동할 준비가되었습니다. 모두 내 질문은 비록 내가 호출 프로그램/클라이언트에서 WCFServiceClient를 만들 때 온다.

클라이언트에 노출 된 내 메서드를 정의하는 내 ServiceContract/인터페이스에서 일부 엔터티 개체와 관련된 많은 메서드가 있다고 가정 해 보겠습니다. 어떻게하면 특정 엔터티의 모든 관련 메서드를 논리적으로 그룹화 할 수 있으므로 내 코드에서는

과 같이 표시됩니다.

WCFServiceClient.Entity1.Insert(); 
WCFServiceClient.Entity1.Delete(); 
WCFServiceClient.Entity1.GetAll(); 
WCFServiceClient.Entity1.GetById(int id); 

WCFServiceClient.Entity2.AddSomething(); 
WCFServiceClient.Entity2.RemoveSomething(); 
WCFServiceClient.Entity2.SelectSomething(); 

...

대신

WCFServiceClient.Insert(); 
WCFServiceClient.Delete(); 
WCFServiceClient.GetAll(); 
WCFServiceClient.GetById(int id); 
WCFServiceClient.AddSomething(); 
WCFServiceClient.RemoveSomething(); 
WCFServiceClient.SelectSomething(); 

나는이 말이 희망

. 나는 구글을 수색했지만, 내 자신의 논리적 인 추론을 시도했지만 운이 없다. 어떤 아이디어라도 감사 할 것입니다.

샷 후안

+0

환영합니다! 코드를 게시 할 때 툴바에서 '코드 포맷'버튼 ('101')을 클릭하여 올바르게 포맷하십시오. – SLaks

답변

0

WCFServiceClient.Entity1.Insert();

WCFServiceClient.Entity2.AddSomething();

이 두 개의 별도의 서비스 인터페이스 냄새 - 각 서비스 계약 (인터페이스) 단일 엔티티 유형에 필요한 모든 방법을 처리 할 수 ​​있습니다 : 당신이 원하는 경우

[ServiceContract] 
interface IEntity1Services 
{ 
    [OperationContract] 
    void Insert(Entity1 newEntity); 
    [OperationContract] 
    void Delete(Entity1 entityToDelete); 
    [OperationContract] 
    List<Entity1> GetAll(); 
    [OperationContract] 
    Entity1 GetById(int id); 
} 

[ServiceContract] 
interface IEntity2Services 
{ 
    [OperationContract] 
    void AddSomething(Entity2 entity); 
    [OperationContract] 
    void RemoveSomething(Entity2 entity); 
    [OperationContract] 
    SelectSomething(Entity2 entity); 
} 

, 당신은 하나를 가질 수를 실제로 두 인터페이스를 모두 구현하는 서비스 클래스 - 완전히 가능하고 유효합니다.

class ServiceImplementation : IEntity1Services, IEntity2Services 
{ 
    // implementation of all seven methods here 
} 

또는 두 개의 개별 서비스 구현 클래스를 만들 수 있습니다. 이는 완전히 다릅니다.

class ServiceImplementation1 : IEntity1Services 
{ 
    // implementation of four methods for Entity1 here 
} 

class ServiceImplementation2 : IEntity2Services 
{ 
    // implementation of three methods for Entity2 here 
} 

그게 도움이 되나요?

+0

네, 고마워요. 어제 내가 한 것은 부분 클래스를 작성하고, 클래스의 각 구현은 다른 servicecontract를 구현하는 것뿐만 아니라 동일한 서비스의 각 계약에 대해 엔드 포인트를 작성하는 것입니다. – Juan

2

당신은 정말 그렇게 할 수 없습니다. 가장 좋은 방법은 하나의 서비스 계약에 모든 "엔터티 1"메서드를 넣고 다른 하나에는 모든 "엔터티 2"메서드를 넣는 것입니다. 단일 서비스는 여러 서비스 계약을 구현할 수 있습니다.

+0

그건 내 다음 계획이었을 것입니다.하지만 내 고객은 Service2에 대한 web.config에 다른 참조를 추가해야한다는 것을 의미합니까? – Juan

+0

@Juan : no. 두 가지 계약을 맺은 하나의 서비스입니다. –

+0

좋아, 그럼 조금 길어. WCF 서비스 구성 편집기에서 여러 계약에 대해이 서비스를 구성하는 방법은 무엇입니까? – Juan

관련 문제