구성 WCF 중 하나를 사용하려면 두 끝점
-
23-09-2019 - |
문제
을 구성하는 방법 WCF 사 나 의 두 끝점에 사용할 수 있?
내가 필요로 두 개의 TCP 포트(따라서 사용 netTcpBinding
).서비스 호스트를 바인딩하는 첫 번째 포트입니다.그것이 실패하는 경우,단지 그것이 실패하는 경우,그것은 바인딩하려고 두 번째 포트입니다.
편집
나는 그것을 알 수 있는 작은 프로그래밍 방식으로,하지만 나의 의도는 그것을 하는 선언적으로(사용 .config
파일에만).
해결책
종점 주소를 포함하여 포트번호를 설정할 수 있는 코드에서 어떤 시점에서 프로세스를 열기 전에 연결이 사용하는 프록시는 개체입니다.그래서 당신은 설정할 수 있습니다 주소 테스트 연결,그리고 그것이 실패하는 경우,다른 항구입니다.여기에는 코드는 희망 보여줍니다.
Dim oProxy as New YourWCFServiceType()
oProxy.Endpoint.Address = New System.ServiceModel.EndpointAddress(New Uri("The address and port number you want to try first"))
Dim FirstBindingSucceeded as Boolean
Try
oProxy.Open()
FirstBindingSucceeded = True
Catch
End Try
If FirstBindingSucceeded = False Then
oProxy.Endpoint.Address = New System.ServiceModel.EndpointAddress(New Uri("The address and port number you want to try second"))
End If
oProxy.Open()
다른 팁
On the server side there is no problem exposing a service with two bindings.
But on the client side you will get a duplicate contract error (or words to that effect)
One way to do it is to create two interfaces (contracts) that are identical except for the name.
You have a single copy of the implementation, each service inherits from this implementation.
You then have two services on different ports, that have the same implementation / functionality.
On the client you then need to program that it first attempts the first port and then if that fails it attempts the second.