C# wcf:动态调用返回复合类型的服务
所以我遇到了这样的情况:C# wcf:动态调用返回复合类型的服务,c#,wcf,C#,Wcf,所以我遇到了这样的情况:a需要调用B服务,a只知道B地址,而且只在运行时知道。但双方事先有相同的服务合同 到目前为止,我有这个(在A): 使用(ChannelFactory scf=newchannelfactory(new BasicHttpBinding(),“B的地址”)) { var channel=scf.CreateChannel(); 通道.GetData(5); ... } [服务合同] 公共接口IService1 { [经营合同] 字符串GetData(int值); [经营合同
a
需要调用B
服务,a
只知道B
地址,而且只在运行时知道。但双方事先有相同的服务合同
到目前为止,我有这个(在A
):
使用(ChannelFactory scf=newchannelfactory(new BasicHttpBinding(),“B的地址”))
{
var channel=scf.CreateChannel();
通道.GetData(5);
...
}
[服务合同]
公共接口IService1
{
[经营合同]
字符串GetData(int值);
[经营合同]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
[数据合同]
公共类复合类型
{
[数据成员]
公共布尔布尔值
...
[数据成员]
公共字符串字符串值
...
}
B
公开相同的服务合同
现在是问题。使用
GetData
一切正常,但是使用接受并返回复合类型的GetDataUsingDataContract
时,似乎B
接收具有默认值的对象,而不是发送的对象。可能有什么问题?将复合类型
放入程序集C,并引用A和B中的内容。是程序集C中定义的由A和B使用的复合类型
?如果没有,它是在哪里定义的?@Daniel Hilgarth它在A和B的定义是相同的。嗯,我来试试。@Daniel Hilgarth是的,它成功了!谢谢。很好:-)我把它作为答案贴了出来,请投票并接受,谢谢。
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
...
}