WCF 服务可以返回另一个服务吗?
代码:
[ServiceContract]
public interface IServiceA
{
[OperationContract]
IServiceB GetServiceB();
[ServiceContract]
public interface IServiceB
{
public class ServiceA : IServiceA
{
public IServiceB GetServiceB()
{
return new ServiceB();
}
以及一个激活调用 ServiceB 的 ServiceA 的表单:
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.ServiceAClient client = new
ServiceReference1.ServiceAClient();
IServiceB serviceB = client.GetServiceB();
当然,这是无法做到的,因为 GetServiceB() 在像这样进行转换时返回对象而不是服务:
IServiceB serviceB = (ServiceB) client.GetServiceB();
我得到 CommunicationException:“现有连接被远程主机强行关闭”