自分のマシンでこのアプリをテストしているときに小さなwcfアプリを作成すると機能しますが、同じネットワーク内の自宅にある別のPCでwcfサーバーエンドを実行すると、エラーが発生します 。 authentication.ProtectionLevelまたはImpersonationLevel、あるいはその両方を増やしてみてください。
両方のPCが同じワークグループにあり、お互いにアクセスできます。私は答えを見つけようとしますが、人々はこれがファイアウォールの問題であると言います。だから私は両方のPCでファイアウォールを無効にしますが、それでも問題が発生します。これが私のサンプルコードです。ホームネットワークの2台のPCでこのwcfアプリを実行する方法を教えてください。ありがとう
サービス終了
namespace WCFSample
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string MyName(string name);
}
}
namespace WCFSample
{
public class Service1 : IService1
{
public string MyName(string name)
{
return string.Format("My Name... {0}", name);
}
}
}
namespace ConsoleApplication1
{
class Program
{
static ServiceHost customerHost = null;
static void Main(string[] args)
{
try
{
HostCustomerService();
Console.WriteLine();
Console.WriteLine("Press any key to stop the services.");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
customerHost.Close();
}
}
private static void HostCustomerService()
{
customerHost = new ServiceHost(typeof
(Service1));
ServiceEndpoint tcpEndpoint = customerHost.AddServiceEndpoint(
typeof(IService1), new NetTcpBinding(),
"net.tcp://192.168.1.103:9020/Service1");
customerHost.Open();
Console.WriteLine("{0} {1}", tcpEndpoint.Address, tcpEndpoint.Name);
Console.WriteLine();
}
}
}
クライアントエンド
namespace Client1
{
class Program
{
static void Main(string[] args)
{
IService1 channel = null;
var endPoint = new EndpointAddress(
"net.tcp://192.168.1.103:9020/Service1");
channel = ChannelFactory<IService1>.CreateChannel(new NetTcpBinding(), endPoint);
Console.WriteLine("Enter Name");
string line = Console.ReadLine();
Console.WriteLine(channel.MyName(line));
Console.ReadKey();
}
}
}