简体   繁体   English

WCF服务方法参数

[英]WCF service method arguments

I have a basicHttpBinding WCF service. 我有一个basicHttpBinding WCF服务。 Via the contract I expose a method that takes in as an argument an IEnumerable<myType> . 通过合同,我公开了一个方法,该方法将IEnumerable<myType>作为参数。 myType class inherits from ISerializable and I implement GetObjectData() and the constructor to myType(SerializationInfo info, StreamingContext context) myType类继承自ISerializable ,我实现了GetObjectData()并将构造函数实现为myType(SerializationInfo info, StreamingContext context)

When I leave the method in my WCF contract that takes IEnumerable<myType> as an argument, I can no longer really use the service. 当我将方法以IEnumerable<myType>作为参数保留在WCF合同中时,我将无法再使用该服务。 I'm able to add a reference but it doesn't actually expose any of the methods I'm expecting. 我可以添加一个引用,但实际上并没有公开我期望的任何方法。

I've done some reading I've seen many people who let people pass arguments to their network methods use the [XmlSerializerFormat] attribute. 我已经阅读了一些文章,看到很多人允许人们使用[XmlSerializerFormat]属性将参数传递给他们的网络方法。

I take it I am trying to use binary serialization and that's not working. 我认为我正在尝试使用二进制序列化,但无法正常工作。 Are there any type of WCF services that lets one transmit binary or do they all have to be XML Serialized? 是否有任何类型的WCF服务可以传输一个二进制文件,或者都必须进行XML序列化? If so how do I make sure myType is XML Serializable. 如果是这样,我如何确保myType是XML可序列化的。

You should read about and implement Data Contract Serialization. 您应该阅读并实现数据合同序列化。 See Using Data Contracts . 请参阅使用数据协定 Do not use the XML Serializer unless you need precise control over the "shape" of the XML on the wire. 除非您需要精确控制线路上XML的“形状”,否则请不要使用XML Serializer。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM