WCF: WSDL-first approach: Problems with generating fault types

前端 未结 2 1290
你的背包
你的背包 2021-02-06 15:05

I\'m currently in the process of creating a WCF webservice which should be compatible with WS-I Basic Profile 1.1. I\'m using a wsdl-first approach (actually for the first time)

相关标签:
2条回答
  • 2021-02-06 15:47

    I think your problem is that you need to add elementFormDefault="qualified" as an attribute to the xsd:schema part of your wsdl. That worked for me.

    0 讨论(0)
  • 2021-02-06 15:58

    I can give you an example of a fault that is being correctly generated for me through svcutil (with /useSerializerForFaults):

    <xsd:schema targetNamespace="http://myproduct.mycompany.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
      <xsd:complexType name="MyError">
        <xsd:sequence>
          <!-- other stuff -->
          <xsd:element name="description" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
    

    Is it possible that you are simply missing the namespace for your types?

    This is the generated code:

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://myproduct.mycompany.com/")]
    public partial class MyError
    {
    
      // other stuff
    
      private string descriptionField;
    
      /// <remarks/>
      [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 1)]
      public string description
      {
        get
        {
          return this.descriptionField;
        }
        set
        {
          this.descriptionField = value;
        }
      }
    }
    

    And this is my full svcutil cmd line statement (note that I am generating a service reference for a given existing service - but it shouldn't make much of a difference in terms of code generation):

    svcutil /t:code /out:C:\MyRepository\GeneratedCode\MyServiceReference.cs /n:*,myproduct.mycompany.servicereference /UseSerializerForFaults C:\MyRepository\*.wsdl C:\MyRepository\*.xsd /config:C:\MyRepository\GeneratedCode\MyServiceReference.config
    
    0 讨论(0)
提交回复
热议问题