【发布时间】:2018-04-16 14:13:32
【问题描述】:
我有一个非常基本的自托管 WCF 控制台应用程序,它托管一个 SOAP 服务。不幸的是,当我查看对服务中方法调用的响应时,序列化的响应实际上是序列化的私有变量而不是公共变量。进行调用的客户端并不期望这种情况,因此在响应中看不到任何有效值。服务代码如下:
using (ServiceHost host = new ServiceHost(typeof(MyService), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
... ...
}
public class MyService: IMyService
{
public MyReturnType MyMethod()
{
return new MyReturnType();
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2612.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")][System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.aaa123.com/WebServices")]
public partial class MyReturnType {
private string myPropertyField;
public string MyProperty { get { return myPropertyField; } set { this.myPropertyField = value; } }
所以在上面对 MyMethod 的调用中,我会看到响应 XML 中的属性定义为 myPropertyField,而不是 MyProperty。
有没有办法改变这种行为?
【问题讨论】:
标签: c# soap datacontractserializer