我有一个使用Web套接字在Visual Studio 2015(c#)中编写的WCF服务,这意味着端点配置了netHTTPBindings。我有一个Delphi应用程序,我目前在XE中编写并希望使用WCF服务,Delphi应用程序使用Web套接字WCF服务的最佳方法是什么?
//编辑-------------------------------------------- -------------------------------
我现在正在使用wsDualHttpBindings,这里有一些原型代码:
WCF服务接口
[ServiceContract(CallbackContract = typeof(IStatusCallback))]
public interface IStatusService
{
[OperationContract(IsOneWay = true)]
Task StartSendingStatus();
}
[ServiceContract]
public interface IStatusCallback
{
[OperationContract(IsOneWay = true)]
Task SendStatus(string aValue);
}
实施
public class StatusService : IStatusService
{
public async Task StartSendingStatus()
{
var callback = OperationContext.Current.GetCallbackChannel<IStatusCallback>();
while (((IChannel)callback).State == CommunicationState.Opened)
{
await callback.SendStatus(GetStatus());
await Task.Delay(1000);
}
}
private string GetStatus()
{
// For now return datetime
string dt = DateTime.UtcNow.ToString();
return Convert.ToString(dt);
}
}
以下是我在C#应用程序中使用它的方法,我将结果放入列表框中。
public partial class ClientForm : Form
{
private StatusServiceReference.StatusServiceClient StatusService;
private class CallbackHandler : StatusServiceReference.IStatusServiceCallback
{
private ListBox _listbox;
public CallbackHandler(ListBox aListBox)
{
_listbox = aListBox;
}
public void SendStatus(string aValue)
{
_listbox.Items.Add(aValue);
_listbox.SelectedIndex = _listbox.Items.Count - 1;
}
}
public ClientForm()
{
InitializeComponent();
var context = new InstanceContext(new CallbackHandler(StatusListBox));
StatusService = new StatusServiceReference.StatusServiceClient(context);
}
private void StatusBtn_Click(object sender, EventArgs e)
{
StatusService.StartSendingStatus();
}
}
这很好用,我想知道在Delphi中执行上述客户端代码的最佳方法。当我导入WSDL文件时,它没有IStatusServiceCallback接口。