【问题标题】:wcf - creating datacontractwcf - 创建数据契约
【发布时间】:2012-01-24 10:51:16
【问题描述】:

我的任务是编写 WCF 服务。 (以前没有这样做过。)我已经收到了我将收到的 xml 的 xsd,我正在尝试将其转换为数据合同。不过我需要帮助。

部分xml的示例是:

<tfsChequeId xmlns="http://www.something.com/XMLSchemas/itrs/tfs/v1">
        <dic numericCode="20010411199194813505"/>
    </tfsChequeId>

到目前为止我所做的是:

    [DataContract]
public class TFSChequeDic
{
    [DataMember]
    public string dic { get; set; }

}

如何指定 numericCode 属性?

如有任何帮助,我们将不胜感激。

亲切的问候, 菲奥娜

更新 向我提供了许多 XSD。这些都相当复杂。在使用 svcutil.exe 生成数据合同时,生成了许多错误。 以下所有形式:

Error: There was a validation error in the schemas provided for code generation:

Source:
Line: 85 Column: 6


Validation Error: Type 'http://www.something.com/XMLSchemas/itrs/common/v1:Docu
mentIdentifierCode' is not declared, or is not a simple type.

生成的数据合约如下:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="TfsChequeId", Namespace="http://www.something.com/XMLSchemas/itrs/tfs/v1")]
public partial class TfsChequeId : object, System.Runtime.Serialization.IExtensibleDataObject
{

    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    private www.something.com.XMLSchemas.itrs.tfs.v1.TfsChequeIdDic dicField;

    public System.Runtime.Serialization.ExtensionDataObject ExtensionData
    {
        get
        {
            return this.extensionDataField;
        }
        set
        {
            this.extensionDataField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)]
    public www.something.com.XMLSchemas.itrs.tfs.v1.TfsChequeIdDic dic
    {
        get
        {
            return this.dicField;
        }
        set
        {
            this.dicField = value;
        }
    }
}

但是我不知道如何使用它.. 即设置 numericCode? 任何想法/提示/提示将不胜感激。

菲奥娜

【问题讨论】:

    标签: c# wcf datacontract


    【解决方案1】:

    您无需手动操作。如果您向SvcUtil 提供WSDL,SvcUtil 将为您生成一个客户端代理。还是您自己创建服务?

    【讨论】:

    【解决方案2】:

    使用 xsd 工具从提供的 xsd 创建一个类对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多