开发者

WCF: collection proxy type on client

I have the following type in wsdl (it is generated by third party tool):

<xsd:complexType name="IntArray">
  <xsd:sequence>
    <xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:int" /> 
  </xsd:sequence>
</xsd:complexType>

Sometimes Visual Studio generates:

public class IntArray : System.Collections.Generic.List<int> {}

And sometimes it doesn't generate any proxy type for this wsdl and just uses int[].

Collection type in Web Service configuration is System.Array.

What could be the reason for such upredictable behavior?

Edited:

I found the way how I can reproduce this behavior.

For examle we have two types:

<xsd:complexType name="IntArray">
  <xsd:sequence>
    <xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:int" /> 
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="StringArray">
  <xsd:sequence>
    <xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:string" /> 
  </xsd:sequence>
</xsd:complexType>

VS generates:

public class IntArray : System.Collections.Generic.List<int> {}

public class StringArray : System.Collections.Generic.List<string> {}

Now I change StringArray type:

<xsd:complexType name="StringArray">
  <xsd:sequence>
    <xsd:element maxOccurs="unbounded" minOccurs=开发者_JAVA技巧"0" name="Elements" type="xsd:string" /> 
    <xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
  </xsd:sequence>
  <xsd:anyAttribute namespace="##any" processContents="lax"/>
</xsd:complexType>

VS generates proxy type for StringArray only. But not for IntArray.

Edited:

Reference.svcmap:

  <ClientOptions>
    <GenerateAsynchronousMethods>false</GenerateAsynchronousMethods>
    <EnableDataBinding>true</EnableDataBinding>
    <ExcludedTypes />
    <ImportXmlTypes>false</ImportXmlTypes>
    <GenerateInternalTypes>false</GenerateInternalTypes>
    <GenerateMessageContracts>false</GenerateMessageContracts>
    <NamespaceMappings />
    <CollectionMappings />
    <GenerateSerializableTypes>true</GenerateSerializableTypes>
    <Serializer>Auto</Serializer>
    <ReferenceAllAssemblies>true</ReferenceAllAssemblies>
    <ReferencedAssemblies />
    <ReferencedDataContractTypes />
    <ServiceContractMappings />
  </ClientOptions>


If you view all files for the project and then view the file called Reference.svcmap for the appropriate service reference could you please let me know what the following config options are in the xml?

<ExcludedTypes />
<ImportXmlTypes>false</ImportXmlTypes>
<GenerateInternalTypes>false</GenerateInternalTypes>
<GenerateSerializableTypes>false</GenerateSerializableTypes>
<Serializer>Auto</Serializer>

Sorry about putting it in as an answer but it was horribly unreadable in the comments.

Edit

Ok, so what is happening here is following:

  1. You are using auto for the serializer.
  2. The default is DataContractSerializer
  3. When generating the proxy code, there is a check for forbidden xsd elements.
  4. If forbidden elements are found, the XmlSerializer is used.

In your case, adding the xsd:any element is causing the serialization mode to change. If you want consistent serialization, you will have to remove the forbidden element or force the proxy generation to use XmlSerialization all the time.

Here is a link about the allowable schema elements for the DataContractSerializer.

Cheers -Leigh


As far as I know, proxy classes are generated by SvcUtil.exe why do not you look at it with reflector...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜