私は 2 つの単純なコンソール アプリケーションを作成しました。1 つは wcf サービスをホストし、もう 1 つは wcf サービス クライアントです。
1 台のマシン (ホストとクライアント) で両方のアプリケーションを実行すると問題なく動作しますが、クライアントまたはホストを別のマシンに移動EndpintNotFountException
しようとすると、ホストに接続しようとすると発生します。
これは私のサービスのコードです:
namespace ConsoleApplication7
{
using System.ServiceModel;
[ServiceContract]
public interface ISimpleService
{
[OperationContract]
void Register(string name);
}
}
そして実装クラス:
namespace ConsoleApplication7
{
public class SimpleService : ISimpleService
{
public void Register(string name)
{
DataBase.Save(name);
}
}
}
ご覧のとおり、非常にシンプルなサービスです:)
これはホスト プログラムのコードです。
using System;
using System.ServiceModel;
class Program
{
static void Main(string[] args)
{
var service = new ServiceHost(typeof(SimpleService));
service.Open();
while (true)
{
Console.ReadLine();
foreach (var s in DataBase.Get())
{
Console.WriteLine(s);
}
}
}
}
サービスを開き、Enter キーを押すと、データベースの内容が出力されます。私はそれが他のものを持っていないことを知っていますがClose()
、それは私の問題を示すためだけです.
app.config
ファイルは次のとおりです。
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name ="myBinding">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<client />
<services>
<service name="ConsoleApplication7.SimpleService" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="myBinding" contract="ConsoleApplication7.ISimpleService"/>
<endpoint address="" binding="basicHttpBinding" contract="ConsoleApplication7.ISimpleService"/>
<endpoint address ="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9101"/>
<add baseAddress="http://localhost:9102"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior" >
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
クライアントコード:
using System;
using System.ServiceModel;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Click to open");
Console.ReadLine();
try
{
var service = new ServiceReference1.SimpleServiceClient(new BasicHttpBinding(), new EndpointAddress("http://192.168.1.11:9102/"));
service.Open();
service.Register("itsMe");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
}
クライアントapp.config
はビジュアルスタジオがAddServiceReference
オプションで作成。
と の両方をベース アドレスとしてapp.config
試したファイルをホストします。http://localhost:9102
http://192.168.1.11:9102
1 台のマシンでホスト アプリケーションとクライアント アプリケーションを開くと、問題なく動作します。それらのアプリの1つを他のマシンに移動するとSystem.EndpointNotFoundException
、実行時に戻りますclient.Open()
。
私が間違っているかもしれないアイデアはありますか?私はnet.tcp
バインディングを試してみましたが、同じ結果になりました。
両方のマシンで Windows ファイアウォールが無効になっている