我有简单的WCF服务和简单的控制台应用程序。使用WebSocket4Net从服务接收消息的控制台应用程序。但是当运行应用程序的服务没有收到任何服务。为什么?如何强制服务发送消息?
服务1:
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);
}
}
配置:
<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>
控制台应用
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());
}
}
}