【发布时间】:2011-11-12 10:10:51
【问题描述】:
我目前正在开发一个 C# Windows 窗体应用程序,我打算让它与服务器交互。服务器将接收来自我开发的移动应用程序的帖子,每当收到帖子时,我的 Windows 窗体应用程序都会收到通知并给我一个通知。
例如我的移动应用程序向我的服务器发送了一条消息。一旦我的服务器收到消息,我的 Windows 窗体应用程序应该会显示一条新通知,显示收到的消息内容。
我现在开始开发我的 WCF 服务,这就是我目前所做的
[ServiceContract(Namespace = "Posting")]
public interface IPostingService
{
[OperationContract]
void NotifyAboutPosting(Posting post);
}
[DataContract]
public class Posting
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public DateTime PostingTimestamp { get; set; }
}
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost/");
ServiceHost selfHost = new ServiceHost(typeof(Posting), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(
typeof(IPostingService),
new WSHttpBinding(),
"Posting");
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
}
关于发帖类,我想问的是里面有哪些方法是用来从服务器获取信息的?
服务完成后如何从这里继续。 (我的 winform 应用程序已经完成,剩下的就是添加这个逻辑,以便在移动应用程序发送到服务器时接收发布。
似乎有一个编译错误
在服务“##.Posting”实施的合同列表中找不到合同名称“##.IPostingService”。
谁能帮我解决这个问题?谢谢一百万!
【问题讨论】:
标签: wcf