2011-10-22 9 views
5

मैं एक ऐसे वेब सेवा के लिए क्लाइंट बना रहा हूं जो मेरे नियंत्रण से कम या कम हो। यहां स्कीमा का एक सरल नमूना दिया गया है:कैसे एक वेब सेवा से सी # डब्ल्यूसीएफ प्रॉक्सी उत्पन्न करने के लिए svcutil का उपयोग करें जो तत्वों को छिपाने के लिए प्रतिबंध का उपयोग करता है?

<xs:complexType name="A"> 
    <xs:sequence> 
     <xs:element minOccurs="0" maxOccurs="1" name="element1" type="xs:string" /> 
     <xs:element minOccurs="0" maxOccurs="1" name="element2" type="xs:string" /> 
    </xs:sequence> 
</xs:complexType> 

<xs:complexType name="B"> 
    <xs:complexContent> 
     <xs:restriction base="A"> 
      <xs:sequence> 
       <xs:element minOccurs="1" maxOccurs="1" name="element2" type="xs:string" /> 
      </xs:sequence> 
     </xs:restriction> 
    </xs:complexContent> 
</xs:complexType> 

संक्षेप में हमारे पास एक ऑब्जेक्ट ए है जिसमें सभी तत्व शामिल हैं। सेवा ए पर आधारित कई प्रकार हैं लेकिन प्रतिबंधों के साथ ताकि विरासत प्रकार आमतौर पर बेस प्रकार से छोटे होते हैं - यहां बी बी

विज़ुअल स्टूडियो 2010, सोपयूआई आदि जैसे स्कीमा दर्शक में उदाहरण दिया गया है। यह उम्मीद के रूप में दिखता है। ए में 2 तत्व हैं और बी केवल 1 (= तत्व 2) है।

का उपयोग कर svcutil मैं अपने दोनों प्रकार के तत्वों का पूरा सेट मिल एक & बी, या जब विकल्पों के साथ खेल रहा जैसे त्रुटि संदेश प्राप्त द्वारा:

Error: Type 'B' in namespace 'http://tempuri.org/XMLSchema.xsd' cannot be imported. Complex types derived by restriction not supported. Either change the schema so that the types can map to data contract types or use ImportXmlType or use a different serializer.

क्षेत्रों छिपाई जा रही है/विरासत में मिला प्रकार में गुण है एक अभ्यास/सड़क नहीं है जिसे मैं यात्रा करना चाहता हूं लेकिन अगर मैं प्रदाता को डब्लूएसडीएल को बदलने के लिए नहीं मिल पाता तो ऐसा लगता है कि मुझे इसे इस तरह करना है।

क्या svcutil के विकल्प हैं जो इसे ठीक से संभालते हैं या क्या मुझे अपने प्रॉक्सी को हाथ-कोड करना है?


अद्यतन 1

के रूप में जॉन सॉन्डर्स से कहा मैं svcutil से सुझाव के परिणाम नहीं दिखाई है। यही कारण है कि आंशिक रूप से पद छोटा रखने का था ... लेकिन यहाँ जाता है:

svcutil schema.xsd/importXmlTypes/datacontractonly में परिणाम:

[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] 
[System.Runtime.Serialization.DataContractAttribute(Name="A", Namespace="http://tempuri.org/XMLSchema.xsd")] 
public partial class A : object, System.Runtime.Serialization.IExtensibleDataObject 
{ 

    private System.Runtime.Serialization.ExtensionDataObject extensionDataField; 

    private string element1Field; 

    private string element2Field; 

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

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)] 
    public string element1 
    { 
     get 
     { 
      return this.element1Field; 
     } 
     set 
     { 
      this.element1Field = value; 
     } 
    } 

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)] 
    public string element2 
    { 
     get 
     { 
      return this.element2Field; 
     } 
     set 
     { 
      this.element2Field = value; 
     } 
    } 
} 

[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] 
[System.Xml.Serialization.XmlSchemaProviderAttribute("ExportSchema")] 
[System.Xml.Serialization.XmlRootAttribute(IsNullable=false)] 

public partial class B : object, System.Xml.Serialization.IXmlSerializable 
{ 

    private System.Xml.XmlNode[] nodesField; 

    private static System.Xml.XmlQualifiedName typeName = new System.Xml.XmlQualifiedName("B", "http://tempuri.org/XMLSchema.xsd"); 

    public System.Xml.XmlNode[] Nodes 
    { 
     get 
     { 
      return this.nodesField; 
     } 
     set 
     { 
      this.nodesField = value; 
     } 
    } 

    public void ReadXml(System.Xml.XmlReader reader) 
    { 
     this.nodesField = System.Runtime.Serialization.XmlSerializableServices.ReadNodes(reader); 
    } 

    public void WriteXml(System.Xml.XmlWriter writer) 
    { 
     System.Runtime.Serialization.XmlSerializableServices.WriteNodes(writer, this.Nodes); 
    } 

    public System.Xml.Schema.XmlSchema GetSchema() 
    { 
     return null; 
    } 

    public static System.Xml.XmlQualifiedName ExportSchema(System.Xml.Schema.XmlSchemaSet schemas) 
    { 
     System.Runtime.Serialization.XmlSerializableServices.AddDefaultSchema(schemas, typeName); 
     return typeName; 
    } 
} 

एक XML- स्तर पर कार्य नहीं वांछनीय है और होगा हमें एक रैपर लिखने के लिए मजबूर करें। गेटगो से प्रॉक्सी को संभालना आसान है।

svcutil schema.xsd/serializer: XmlSerializer/डेटाकंट्रैक्टोनली नीचे दी गई त्रुटि देता है और यही कारण है कि मैं वैकल्पिक टूल के लिए पूछ रहा हूं।

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema.xsd")] 
[System.Xml.Serialization.XmlRootAttribute("request", Namespace="http://tempuri.org/XMLSchema.xsd", IsNullable=false)] 
public partial class B : A { 
} 

/// <remarks/> 
[System.Xml.Serialization.XmlIncludeAttribute(typeof(B))] 
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema.xsd")] 
public partial class A { 

    private string element1Field; 

    private string element2Field; 

    /// <remarks/> 
    public string element1 { 
     get { 
      return this.element1Field; 
     } 
     set { 
      this.element1Field = value; 
     } 
    } 

    /// <remarks/> 
    public string element2 { 
     get { 
      return this.element2Field; 
     } 
     set { 
      this.element2Field = value; 
     } 
    } 
} 
+0

आपको लगता है कि त्रुटि संदेश के किस हिस्से समझ में नहीं आया? यह आपको बताता है कि समस्या को कैसे हल किया जाए। –

+2

नहीं, यह मुझे वांछित परिणाम नहीं देता है (यह भी ध्यान दें कि मैंने संदेश जैसे कहा - यह सिर्फ एक नमूना था - एक गरीब जिसे मैं जानता हूं ...)। यदि आपने उन विकल्पों का उपयोग करने का प्रयास किया है तो आप देखेंगे कि यह प्रासंगिक गुणों के साथ प्रॉक्सी उत्पन्न नहीं करता है।नतीजा यह है कि मैं तत्वों और serializtion की सूची के साथ सीधे निपटने के साथ समाप्त होता है। –

+1

मुझे उन विकल्पों को आजमाने में कोई रूचि नहीं है। _You_ ने उन्हें आजमाया है, और _you_ परिणामों को जानते हैं। कृपया ** हमें दिखाएं कि आपने क्या किया है, और ** ** हमें परिणाम दिखाएं। –

उत्तर

0

त्रुटि संदेश या तो /importXmlTypes स्विच का उपयोग करने के लिए, या बदलने के लिए आपको बता रहा है:

svcutil schema.xsd /serializer:XmlSerializer /datacontractonly Error: Type 'B' in namespace 'http://tempuri.org/XMLSchema.xsd' cannot be imported. Complex types derived by restriction not supported. Either change the schema so that the types can map to data contract types or use ImportXmlType or use a different serializer.

If you are using the /dataContractOnly option to import data contract types and are getting this error message, consider using xsd.exe instead. Types generated by xsd.exe may be used in the Windows Communication Foundation after applying the XmlSerializerFormatAttribute attribute on your service contract. Alternatively, consider using the /importXmlTypes option to import these types as XML types to use with DataContractFormatAttribute attribute on your service contract.

XSD schema.xsd/सी का उपयोग करते हुए एक ग्रुप बी कि छुपा element1 के बिना एक विरासत में देता है XmlSerializer का उपयोग करने के लिए। मदद से:

/importXmlTypes - Configure the Data Contract serializer to import non-Data Contract types as IXmlSerializable types.

और

/serializer:XmlSerializer - Generate data types that use the XmlSerializer for serialization and deserialization

+2

हां मुझे पता है लेकिन ऐसा करने से मुझे टाइप बी होने का वांछित परिणाम नहीं मिलता है जिसमें केवल तत्व 2 नामक संपत्ति शामिल होती है। –

+0

"ऐसा करना?" क्या मैंने _two_ चीजों को दिखाया है जो मैंने आपको दिखाया? आपका रिजल्ट क्या था? अपने प्रश्न को आपके द्वारा किए गए शोध के साथ अपडेट करें और हमें दिखाएं कि परिणाम क्या था। –

संबंधित मुद्दे

 संबंधित मुद्दे