WCF send message to client

510 Views Asked by At

I have simple WCF service and simple console application. Console application using WebSocket4Net to receive message's from service. But when services running application do not receive anything from service. Why? How to force service send message?

Service1:

namespace WcfServiceLibrary2
{
public class Service1 : IService1
{
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "data/{id}")]
        public Person GetData(string id)
        {
            // lookup person with the requested id 
            return new Person()
            {
               id=id,
               Name="John"
            };
        }
}
public class Person
{
    public string Name { get; set; }
    public string id { get; set; }
}
}

IService1:

namespace WcfServiceLibrary2
{
[ServiceContract]
public interface IService1
{
    [OperationContract]
    Person GetData(string id);
}
}

config:

<configuration>
<system.serviceModel>
<services>
  <service name="WcfServiceLibrary2.Service1">
    <endpoint address="http://localhost:8732/service1" 
              binding="webHttpBinding" 
              contract="WcfServiceLibrary2.IService1"/>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior>
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

Console application

namespace ConsoleApplication9
{
class Program
{
    static void Main(string[] args)
    {
        GetData getData = new GetData();
    }
}
public class GetData
{
    private Client socket;
    public GetData()
    {
        socket = new Client("http://localhost:8732/Service1/data/12");
        socket.Message += Message;
    }
    private void Message(object sender, MessageEventArgs e)
    {
        Console.WriteLine(e.Message.Encoded.ToString());
    }
}
}
0

There are 0 best solutions below