0

自分のマシンでこのアプリをテストしているときに小さな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();
    }

 }
 }
4

1 に答える 1

0

デフォルトでは、NetTcpBindingにはセキュリティで保護されたチャネルが必要だと思います。

バインディングを作成するとき(クライアントとサーバー上で)、代わりに:

new NetTcpBinding()

試す:

new NetTcpBinding(SecurityMode.None)

于 2012-10-28T18:33:27.280 に答える