2016-11-07 13 views
0

私は2つのアプリケーションにWCFサービスともう1つはWCFクライアントを持っています。WCFクライアントは動的ポートを使用してサービスに接続できません

静的ポートを使用すると、それらの間の接続は正常に機能します。

ポート番号として「0」を渡すと、WCFサービスは動的に利用可能なポートを取得します。

クライアントはポートを取得してそのポートをサーバーに渡しますが、接続は常に「EndpointNotFoundException」および「Address Filter Mismatch」で終了します。

"MetaData"のバインディングが役に立たないとコメントしました。

//IP address is determined by code, for simplicity in this example it is hardcoded 
//set port to 0 to get a free port 
var url = $"net.tcp://190.150.140.22:0/UiHost"; 
var UiHost = new ServiceHost(typeof(ShippingUIService), new Uri(url)); 

//var mBehave = new ServiceMetadataBehavior(); 
//UiHost.Description.Behaviors.Add(mBehave); 

var ntb = new NetTcpBinding(SecurityMode.None) { ListenBacklog = 10, MaxConnections = 20, PortSharingEnabled = false }; 

var endPoint = UiHost.AddServiceEndpoint(typeof(Core.IShippingUIService), ntb, ""); 
//UiHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); 
// Tell WCF to actually bind to a free port instead of 0 
endPoint.ListenUriMode = System.ServiceModel.Description.ListenUriMode.Unique; 

UiHost.Open(); 

//Uri is saved, so the client can access the service 
var serviceHostUri = UiHost.ChannelDispatchers.First().Listener.Uri.AbsoluteUri; 
log.Info($"UI Service started. With address {serviceHostUri}"); 

このビットのコードは、実際のポート番号を返すことはできませんか?

UiHost.ChannelDispatchers.First()。Listener.Uri.AbsoluteUri;

すべてのヒントを事前におねがいします。

答えて

0

サービスホストのデフォルトアドレスフィルタは、動的に割り当てられたポートを認識せずに生成されるため、一致しません。最も簡単な解決策は、あなたのサービスタイプ(ShippingUIService)をAddressFilterMode = AddressFilterMode.Anyを使用して任意のアドレスで応答するように設定することです。

コードの基本的なビット:助け

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] 
class ShippingUIService { 
    // Class members 
} 
+0

どうもありがとう! – Hiram

関連する問題