WCF测试客户端不支持该操作 [英] Operation not supported in the WCF Test Client

查看:73
本文介绍了WCF测试客户端不支持该操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了WCF服务,并且在默认服务中我在主DataContract上添加了另一个操作合同:

I created a WCF service and to the default service I added another operation contract on the main DataContract:

[OperationContract]
void DoSomething(UserData data);

然后,我在下面有类似的内容(出于示例目的而进行了简化).问题是,即使层次结构中的所有类都用DataContract装饰,而其所有成员都用DataMember装饰,当我使用WCF测试客户端时,它还有一个红色图标,指示"WCF测试客户端中不支持该操作".

Then I have something like this (simplified for the purpose of example) below. The problem is that even though ALL classes in the hierarchy are decorated with DataContract and ALL their members decorated with DataMember, when I use the WCF Test Client it has a red icon indicating that "the operation is not supported in the WCF test client".

[DataContract]
public class UserData {
   [DataMember]
   public uint One { get; set; }

   [DataMember]
   public CompositeType Extra { get; set; }

   public UserData() { ctor. code }
}


[DataContract]
public class CompositeType {
    [DataMember]
    public uint Two { get; set; }

    public UserData() { ctor code }
}

推荐答案

将属性添加到"UserData"类 [KnownType(typeof(CompositeType))]

Add the attribute to your 'UserData' class [KnownType(typeof(CompositeType))]

赞:

[DataContract]
[KnownType(typeof(CompositeType))]
public class UserData 
{
   [DataMember]
   public uint One { get; set; }

   [DataMember]
   public CompositeType Extra { get; set; }

   public UserData() { ctor. code }
}

http://msdn.microsoft.com/en-us/library/ms730167.aspx

http://msdn.microsoft.com/en-us/library/system.operatingsystem.aspx

OperatingSystem类具有一些与其他类相关的属性.您可以将所有这些类包括在已知类型中,但是依赖关系链可能会变得很大,因此我强烈建议完全不使用操作系统类.

The OperatingSystem class has a few properties which relate to other classes. You could include all these classes in the known types but the dependency chain could get rather large and I would highly recommend not using the Operating System class at all.

您应该从操作系统类中确定实际需要的信息,并创建自己的DTO以传递回响应中.这样,您可以确保在合同中轻松定义所有类型.

You should work out what information you actually need from the Operating System class and create your own DTO to pass back in the response. That way you can ensure all the types are easily definable on your contract.

这篇关于WCF测试客户端不支持该操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆