少しトリッキーな開発で数日間立ち往生しています。説明:
機能上の必要性: 同じコントラクトを共有する異なるバインディング タイプを持つ一意のサービスを公開し、クライアントの機能で使用するバインディングを実行時に切り替えます (.Net クライアントの場合は net.tcp を使用し、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のものには触れません...そのような変更を行うことは可能ですか? それとも、これらのエンドポイントは、同じコントラクトを永久に共有することを意図していますか?