WPF,使用Wdsl元,Codedom编译问题

问题描述 投票:0回答:1

我正在尝试通过 mex 客户端使用 wdsl。要编译它并在没有引用的情况下使用它。但我收到有关“CS0246:找不到类型或命名空间名称“架构””的编译器错误。

我使用 mexclient 导入合约

    MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);

    mexClient.ResolveMetadataReferences = true;
    mexClient.MaximumResolvedReferences = 1000;
    var metaSet = mexClient.GetMetadata(mexAddress, mexMode);

    WsdlImporter importer = new WsdlImporter(metaSet);
    result.ContractDescriptions = importer.ImportAllContracts();
    result.AllEndpoints = importer.ImportAllEndpoints();

然后我生成并编译它。

    CodeCompileUnit unit = (CodeCompileUnit)importer.State[typeof(CodeCompileUnit)];
    ServiceContractGenerator generator = new ServiceContractGenerator(unit);

    foreach (ContractDescription contract in result.ContractDescriptions)
    {
      generator.GenerateServiceContractType(contract);
    }

    // Generate a code file for the contracts.
    CodeGeneratorOptions codeGeneratorOptions = new CodeGeneratorOptions();
    codeGeneratorOptions.BracingStyle = "C";

    // Create Compiler instance of a specified language.
    CompilerResults results;
    using (CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("CSharp"))
    {

     CompilerParameters compilerParameters = new CompilerParameters(new string[] { 
        "System.dll", 
        "System.Data.dll", 
        "System.ServiceModel.dll", 
        "System.Runtime.Serialization.dll", 
        "System.Xml.dll", 
        "System.Xml.Linq.dll", 
        "System.Xml.Serialization.dll" });

      compilerParameters.GenerateInMemory = true;
      compilerParameters.GenerateExecutable = false;
      compilerParameters.WarningLevel = 1;
      compilerParameters.TempFiles = new TempFileCollection("Compile", true);

      results = codeDomProvider.CompileAssemblyFromDom(compilerParameters, generator.TargetCompileUnit);
}

这导致 错误 CS0246:找不到类型或命名空间名称“架构”(您是否缺少 using 指令或程序集引用?)

当我查看生成的代码时,我可以看到这个未知的类型

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("BfusTester", "1.0.0.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,     Namespace="http://www.logica.com/BusinessForUtilities/2012/LoggerService")]
public partial class TestDS {
    
        private schema schemaField;
    
        private System.Xml.XmlElement anyField;
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.w3.org/2001/XMLSchema",     Order=0)]
        public schema schema {
            get {
                return this.schemaField;
            }
            set {
                this.schemaField = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlAnyElementAttribute(Order=1)]
        public System.Xml.XmlElement Any {
            get {
                return this.anyField;
            }
            set {
                this.anyField = value;
            }
        }
    }

其中“private schema schemaField;”行包含未知类型。该方法在实现中看起来像这样

在界面中

    [OperationContract]
    DataSet Test(DataSet ds);

并投入使用

    public DataSet Test(DataSet ds)
    {
      return new DataSet();
    }

它只是标准的System.Data.DataSet。遗憾的是,该界面不是我可以编辑的。

我正在尝试调整 ServiceContractGenerator 和/或 CodeDomProvider 上的一些选项或引用的程序集,但没有运气。在我看来,这是某种 xml 序列化问题。 希望有人能给我一些建议!

c# xml serialization code-generation
1个回答
0
投票

几天后!

我可以看到导致 CodeDom 生成中出现问题的 DataSet 方法使用“文字”类型。

<wsdl:operation name="Test2">
        <soap12:operation soapAction="http://www.logica.com/BusinessForUtilities/2012/LoggerService/ILoggerService/Test2" style="document"/>
        <wsdl:input>
            <soap12:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap12:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>

我读到的内容告诉“ServiceContractGenerator”以字面方式查找类型。因此,如果错误,我可能需要告诉 WsdlImporter 或 ServiceContractGenerator 在哪里查找 DataSet 类型。但我不知道怎么办!

© www.soinside.com 2019 - 2024. All rights reserved.