Click here to Skip to main content
15,888,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm still learning, and I have a problem connecting to another connected computer in the same network to my simple WCF service using BasicHttpBinding.


A. Common.dll
   [ServiceContract]
    public interface ISampleService
    {
       [OperationContract]
        System.DateTime GetServerTime();
    }

B. Server.dll
 
    public class SampleService : ISampleService
    {
        public DateTime GetServerTime()
        {
            return DateTime.Now;
        }
    }

C. Console host app
 
   static void Main(string[] args)
        {
            string  endPointAddress = "http://localhost:9942/ServiceTest";
            Uri baseAddress = new Uri(endPointAddress);
            var host = new ServiceHost(typeof(SampleService), baseAddress);
            BasicHttpBinding httpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            host.AddServiceEndpoint(typeof(ISampleService), httpBinding, "ISampleService");

            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.HttpGetUrl = new Uri(endPointAddress);
            host.Description.Behaviors.Add(smb);
            host.Open();
            Console.WriteLine("Service up and running at:");
            foreach (var ea in host.Description.Endpoints)
            {
                Console.WriteLine(ea.Address);
            }
            Console.ReadLine();
            host.Close();
        }

D. Client Proxy
   public class ProxyTestService : ClientBase<ISampleService>, ISampleService
   {
       public ProxyTestService(string address)
           :base (new BasicHttpBinding(BasicHttpSecurityMode.None),new EndpointAddress($"http://{address}:9942/ServiceTest/ISampleService"))
       {

       }

       public DateTime GetServerTime()
       {
           return base.Channel.GetServerTime();
       }
   }


When I check on the computer where is the host running it is fine (address = localhost).

However, when I connect from another computer in the network (address = IPCompuerHost) there are various problems:

There was no endpoint listening at http://192.168.1.111:9942/ServiceTest/ISampleService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
InnerException: Unable to connect to the remote server


You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint.

When I use NetTcpBinding, everything is correct. What is different in BasicHttpBinding??

What I have tried:

netsh http add urlacl url=http://+:9942/ServiceTest user=Eugeniusz

netsh advfirewall firewall add rule name="ServiceTest9942" dir=in protocol=tcp localport=9942 profile=private remoteip=localsubnet action=allow

netsh interface portproxy add v4tov4 listenport=9942 listenaddress=192.168.1.111 connectport=9942 connectaddress=192.168.1.1 protocol=tcp
Posted
Comments
F-ES Sitecore 10-Apr-18 7:43am    
Have you tried using the IP rather than "localhost" in your server app?

string endPointAddress = "http://192.168.1.111:9942/ServiceTest";
EugeniuszT 10-Apr-18 8:59am    
Yes,
I've message on Client App: "You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint."

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