Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Greatings from Latvia!
I'm making application with WCF. But it don't working fine.

so IService.cs

namespace WCFSample
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string MyName(string name);
    }
}



Service.cs
namespace WCFSample
{
    public class Service1 : IService1
    {
        public string MyName(string name)
        {
            return string.Format("My Name... {0}", name);
        }

    }
}


Here is Host ConsoleAplication Code. I have added References to Host aplication. (system.ServiceModel and WCFSample
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();

        }
    }
}


And here is Client ConsoleAplicaiton
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();
        }

    }
}


when I run on localhost all works. But when I run client app from another Pc in same subnet -> nothing. Client programm NotResponding.
I have read many literature and I can not find answers. Can someone help me?
Sorry my english.
english. :)
Thanks for answers
Posted
Updated 20-Nov-10 3:43am
v2
Comments
[no name] 20-Nov-10 9:44am    
Use pre tag rather than code tag for code snippets

Thank you, those guys who looked at my Topic.
I have solved my problem.
SO....
on client I put on Try....catch block method (MyName)
then i could to read the error. before then the program was closed.
try
          {
              string line = Console.ReadLine();
              Console.WriteLine(channel.MyName(line));
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.Message);
          }
          Console.ReadKey();

gauged error was

a remote side security requirement was not fulfilled during authentication. TRy increasing the ProtectionLevel and/or ImpersonationLevel

then i changed Security settings on Host app
 static NetTcpBinding bbb = new NetTcpBinding();
......
 ServiceEndpoint tcpEndpoint = customerHost.AddServiceEndpoint(
                typeof(IService1), bbb,
                "net.tcp://192.168.1.102:9020/Service1");
            bbb.Security.Mode = SecurityMode.None;

And on client app....
 NetTcpBinding bbb = new NetTcpBinding();
bbb.Security.Mode = SecurityMode.None;
 
Share this answer
 
Comments
Ken747 6-Aug-12 22:24pm    
thanks for posting your solution valza, it resolved my issue as well :)
have you checked your firewall settings on the machine hosting the service?

if something works local but doesn't over a network, it's the first thing I'd check.
 
Share this answer
 
Comments
valza 20-Nov-10 13:02pm    
I have added port and program to firewall (inbound $ outbound) and I get same problem.

If I turn off firewall on both computers nothing changes! :)
Any other solution?
jim lahey 20-Nov-10 15:30pm    
can the machines ping each other?
valza 20-Nov-10 16:45pm    
he he of course. The computers share files etc.
I use Linksys Wireless router.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900