views:

340

answers:

5

Hi everyone...

I am trying to using Net.TCP in my WCF Service, which is self hosted, when i try to add this service reference through web reference to my client, i am not able access the classes and methods of that service, can any have any idea to achieve this... How I can add web references in this case. My Service has one method (GetNumber) that returns int.

WebService:

public class WebService : IWebService
{
    public int GetNumber(int num)
    {
        return num + 1;
    }
}


Service Contract code:

[ServiceContract]
public interface IWebService
{
    [OperationContract]
    int GetNumber(int num);
}


WCF Service code:

        ServiceHost host = new ServiceHost(typeof(WebService));
        host.AddServiceEndpoint(typeof(IWebService), new NetTcpBinding(), new Uri("net.tcp://" + Dns.GetHostName() + ":1255/WebService"));
        NetTcpBinding binding = new NetTcpBinding();
        binding.TransferMode = TransferMode.Streamed;
        binding.ReceiveTimeout = TimeSpan.MaxValue;
        binding.MaxReceivedMessageSize = long.MaxValue;
        Console.WriteLine("{0}", Dns.GetHostName().ToString());
        Console.WriteLine("Opening Web Service...");
        host.Open();
        Console.WriteLine("Web Service is running on port {0}",1255);
        Console.WriteLine("Press <ENTER> to EXIT");
        Console.ReadLine();


This works fine. Only problem is how to add references of this service in my client application. I just want to send number and to receive an answer. Can anyone help me?

A: 

Your client must have the proxy of your webservice as a class so it can instantiate it and use it to call your webservice methods.

Read here

Konstantinos
A: 

1) Is the service and client running on the same machine, if not is the firewall blocking communication?

2) Have you tried using svcutil to generate the client class (which you can then reference in your client application?

Calanus
A: 

Yes, service and client runnig on the same machine. How I can generate with svcutil?

A: 

Hi, Did you ever get an answer to this? I've got the same problem...amongst others!

bowthy
A: 

just type in add service reference area of visual studio the base address of your configured net.tcp server ( visual studio does not discoveres tcp protocol-based servers automatically so you can point the address manually )

testt