CloudService WCFエンドポイントを移行するステートレスサービスがあります。これらのenpointは一般公開されており、WS-MetadataExchange via を参照してプロパティを検出する必要があります。WCFTestClientからVisual Studioプロジェクトのサービス参照を参照してください。WS-MetadataExchangeを使用したサービスファブリックからWCF/TCPエンドポイントを外部クライアントとWcfTestClientに公開する
<Endpoint Protocol="tcp" Name="WcfServiceEndpoint" Type="Input" Port="8081" />
としてだけでなく、サービス契約を
[ServiceContract]
public interface ITestContract
{
[OperationContract]
int TestMethod(int value1, int value2);
}
方法:
私はいくつかのチュートリアルを踏襲して持ってきたテスト用のエンドポイントを設定
public class TestService : ITestContract
{
public int TestMethod(int value1, int value2)
{
var result = value1 + value2;
return result;
}
}
そして、サービスリスナオーバーライド:
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] { new ServiceInstanceListener((context) =>
new WcfCommunicationListener<ITestContract>(
this.Context,
new TestService(),
WcfUtility.CreateTcpClientBinding(),
"WcfServiceEndpoint"
)
)};
先ほどの私のプロジェクトでは、カスタムServiceHostオブジェクトを設定し、そのバインディング/ URLをカスタマイズすることができました。私はクライアントにサービスをうまく発見させることができました。 WcfTestClientとこのサービスを公開できるようにする必要があります。参照サービスの追加は、WS-MetadataExchangeを使用してプロパティを検出できます。今のところ私はサービスの経路が何であるかについて何の制御もしていません!
理想的には、私はまだのServiceHost使用したい:私は今の私(下)VipulM-MSFTからの提案に基づき
var host = new ServiceHost(ITestContract);
host.AddServiceEndpoint(TestService, new NetTcpBinding(SecurityMode.None), "net.tcp://...", new Uri("net.tcp://..."));
host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
host.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
host.Open();
UPDATE
を最初にコミュニケーションリスナーを作成する:
私は、サービスを作成testCommunicationListener.ServiceHost.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
testCommunicationListener.ServiceHost.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
:
ServiceMetadataBehavior metaDataBehavior = new ServiceMetadataBehavior();
testCommunicationListener.ServiceHost.Description.Behaviors.Add(metaDataBehavior);
と同様に障害で例外の詳細を可能にする:そしてMetadataExchangeを動作を可能にするのServiceHostオブジェクトを変更
var testCommunicationListener = new WcfCommunicationListener<ITestContract>(
this.Context,
new TestService(),
WcfUtility.CreateTcpClientBinding(),
"WcfServiceEndpoint"
);
エンドポイント(サービスへの私の希望するパス):
testCommunicationListener.ServiceHost.AddServiceEndpoint(typeof(ITestContract), new NetTcpBinding(SecurityMode.None), "net.tcp://localhost:8081/Services/Tests", new Uri("net.tcp://localhost:8081/Services/Tests"));
と同様にMexEndpoint(MetaExchangeはTCP上で結合を可能にする):
Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
testCommunicationListener.ServiceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "net.tcp://localhost:8081/Services/Tests/mex", new Uri("net.tcp://localhost:8081/Services/Tests/mex"));
そして最後に、私はステートレスサービスにリスナーを割り当てる:
return new[] { new ServiceInstanceListener((context) => testCommunicationListener)};
私はこれを押すと私のローカルクラスタ私は次のエラーが表示されます:
The Service contains multiple ServiceEndpoints with different ContractDescriptions which each have Name='ITestContract' and Namespace=' http://tempuri.org/ '. Either provide ContractDescriptions with unique Name and Namespaces, or ensure the ServiceEndpoints have the same ContractDescription instance.
Oこの衝突を避けるために、デフォルトのエンドポイントを削除するので、私が試した:
testCommunicationListener.ServiceHost.Description.Endpoints.RemoveAt(0);
呼び出す前に:私は次のエラーを与える
testCommunicationListener.ServiceHost.AddServiceEndpoint(typeof(ITestContract), new NetTcpBinding(SecurityMode.None), "net.tcp://localhost:8081/Services/Tests", new Uri("net.tcp://localhost:8081/Services/Tests"));
Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
testCommunicationListener.ServiceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "net.tcp://localhost:8081/Services/Tests/mex", new Uri("net.tcp://localhost:8081/Services/Tests/mex"));
:
Replica had multiple failures in API call: IStatelessServiceInstance.Open(); Error = System.NullReferenceException (-2147467261) Object reference not set to an instance of an object. at Microsoft.ServiceFabric.Services.Communication.Wcf.Runtime.WcfCommunicationListener
1.b__0(IAsyncResult ar) at System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action
1 endAction, Task`1 promise, Boolean requiresSynchronization)
私が試しました同様の結果を持つ他のバリエーションはほとんどありません。
また、MetadataExchangeの動作rを追加します(追加のエンドポイントは作成しません)。しかしこのシナリオでは、私のエンドポイントのURLがどのように分かっていますか?私はnet.tcp:// localhost:8081/TestService(は とする必要があります)を使ってみましたが、コンソールアプリケーションやWcfTestClientから接続できません。
UPDATE 2
内のみ追加エンドポイントとしてMetadataExchangeBindingを追加して、自分の希望するサービスのパスを割り当てることによって、必要に応じて、私は私のWCFエンドポイントをホストすることができました:あなたは
Binding mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
testCommunicationListener.ServiceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "net.tcp://localhost:8081/Services/Tests/mex", new Uri("net.tcp://localhost:8081/Services/Tests/mex"));
ありがとうございます!私はServiceHostをカスタマイズしようとしましたが、私はまだいくつかの問題に取り組んでいます。私はこれらの試みを含むように私の質問を更新しました。 – CodeAbundance
ありがとうVipulM - 私はあなたの助言のおかげでこれを最後に解決することができました。私の発見を更新します。私は新しい問題にぶつかりました。あなたはここで見てみることができます:http://stackoverflow.com/questions/42845939/wcf-endpoints-exposing-multiple-contracts-in-service-fabric – CodeAbundance