개발이 조금 까다 롭습니다. 설명 :동일한 계약을 갖고 있지만 런타임에 수정하는 호스트를 여러 개 끝내십시오.
기능 요구 사항 : 동일한 계약을 공유하는 다른 바인딩 유형으로 고유 서비스를 노출하고 런타임시 클라이언트의 기능 (예 : .Net 클라이언트, Java 클라이언트, http 바인딩 사용).
<!-- Test Service -->
<service name="TestService.v1.TestServiceImplementation, TestService" behaviorConfiguration="MyBehavior">
<endpoint name="TestServiceV1Htpp" contract="ITestService.v1" address="http://localhost:6001/TestService/v1" binding="basicHttpBinding" bindingConfiguration="HttpConf" behaviorConfiguration="HttpSOAPBehavior"/>
<endpoint name="TestServiceV1NetTcp" contract="ITestService.v1" address="net.tcp://localhost:6002/TestService/v1" binding="customBinding" bindingConfiguration="TcpConfStream" behaviorConfiguration="TcpSOAPBehavior"/>
</service>
TestService dataContract : 내 구성 파일에 누구인지 여기
[ServiceContract(...)]
public interface ITestService : IDisposable
{
[OperationContract]
IEnumerable<string> GetData();
}
[ServiceBehavior(...)]
public class TestServiceImplementation : ITestService
{
public IEnumerable<string> GetData()
{
yield return "Pong";
}
}
그리고 내 계약의 수정 "런타임"(엔드 포인트의 행동, 끔찍한 반환 결과를 가짜로 만들기 위해) :
public sealed class CustomBehavior : IEndpointBehavior
{
void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
foreach (var msg in endpoint.Contract.Operations.First().Messages)
{
var part = msg.Body.ReturnValue;
if (part != null)
part.Type = typeof(Stream);
}
}
}
실행 : 내 CustomBehavior를 사용하지 않는 경우
모든 것이 완벽하게 작동합니다. TCP 끝점 (TcpSOAPBehavior)의 동작 구성에 추가하면 Body.ReturnValue.Type이 수정되고이 수정 내용은 내 끝점 (심지어 http ...)의 모두 계약을 변경합니다. 그저 TCP 끝점 계약을 수정하고 싶지는 않지만 HTTP 하나만 누르면됩니다 ... 그런 수정을 할 수 있습니까? 또는 끝점은 영원히 동일한 계약을 공유하기위한 것입니까?