c# - wcf:动态调用返回复合类型的服务

标签 c# wcf

所以我遇到这样的情况:A需要调用B服务,而A只知道B code> 地址并且仅在运行时。但两者事先都有相同的服务契约(Contract)。

到目前为止,我有这个(在A):

    using (ChannelFactory<IService1> scf = new ChannelFactory<IService1>(new BasicHttpBinding(), "B's adress"))
    {
        var channel = scf.CreateChannel();
        channel.GetData(5);
        ...
    }

    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);
    }
    [DataContract]
    public class CompositeType
    { 
       [DataMember]
       public bool BoolValue
        ...

       [DataMember]
       public string StringValue
        ...
    }

B 公开相同的服务合约。

现在问题来了。使用 GetData 一切正常,但使用 GetDataUsingDataContract 接受并返回复合类型 - 似乎 B 接收具有默认值的对象,而不是具有默认值的对象已经送走了。可能出了什么问题?

最佳答案

CompositeType 放入程序集 C 中,并在 A 和 B 中引用它。

关于c# - wcf:动态调用返回复合类型的服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9720328/

相关文章:

c# - 无论如何,当异常冒出时,我为什么要写 throw ?

c# - 如何更改 ASP.NET Core API 中的默认 Controller 和操作?

wcf 错误 : Incoming message was signed with a token which is different from what used to encrypt body. 这不是预期的

c# - WCF 服务引用使用 XmlSerializer 创建临时动态程序集

c# - WCF 超时问题

c# - Bootstrap Modal 会触发,但不会触发 ASP 按钮单击事件

c# - NullReferenceException 而涉及的对象是有效的

c# - 在通用 Windows 平台中播放声音

c# - 如何在 WCF 服务中使用角色管理器?

c# - WCF 和 SOAP 1.1