2

我必须访问不受我控制的外部服务。所以我通过vs2012添加了一个服务引用,一切都很好。

我可以通过soapUI 检查服务的行为。所以看起来一切正常。

但是在如下初始化客户端后,我注意到 client.InnerChannel 和其他属性大多是错误的。(有些属性有如下错误,有些说服务处于故障状态)

SomeService.SomeServiceV1x1Client client = new SomeService.SomeServiceV1x1Client ();

如果我继续使用client.InnerChannel我会收到以下错误:

XmlSerializer attribute System.Xml.Serialization.XmlChoiceIdentifierAttribute is not valid in Items. 
Only XmlElement, XmlArray, XmlArrayItem, XmlAnyAttribute and XmlAnyElement attributes are supported when IsWrapped is true.

精简版:

是否存在一些常见的不兼容问题wsdl 中的元素会影响导致这种行为的 reference.cs 吗?更重要的是,是否有一种体面的解决方法,而不是……下面的解决方法。这里解释了问题(或多或少),但在这种情况下并没有太大帮助。

长版:

检查wsdl,有这样的部分:

 <xsd:complexType name="getCitizenFromLocalDb">
    <xsd:choice minOccurs="1" maxOccurs="1">
      <xsd:sequence>
        <xsd:element minOccurs="1" maxOccurs="1" name="citizenId" type="profileMgmnt:IdType" />
      </xsd:sequence>
      <xsd:sequence>
        <xsd:element minOccurs="0" maxOccurs="1" name="name" type="xsd:string" />
        <xsd:element minOccurs="0" maxOccurs="1" name="surname" type="xsd:string" /> >
        <xsd:element minOccurs="0" maxOccurs="1" name="birthDate" type="xsd:date" /> 
      </xsd:sequence>
    </xsd:choice>
  </xsd:complexType>

检查 References.cs,

 [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://somwhere.com/SomeService/Service/V4", IncludeInSchema=false)]
public enum ItemsChoiceType {

    [System.Xml.Serialization.XmlEnumAttribute(":birthDate")]
    birthDate,
    [System.Xml.Serialization.XmlEnumAttribute(":citizenId")]
    citizenId,
    [System.Xml.Serialization.XmlEnumAttribute(":name")]
    name,
    [System.Xml.Serialization.XmlEnumAttribute(":surname")]
    surname,
}

public partial class getCitizenFromLocalDbRequest {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("birthDate", typeof(System.DateTime), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="date")]
    [System.Xml.Serialization.XmlElementAttribute("citizenId", typeof(long), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlElementAttribute("name", typeof(string), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlElementAttribute("surname", typeof(string), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
    public object[] Items;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://somewhere.com/SomeService/Service/V4", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public GeneralServices.SomeService.ItemsChoiceType[] ItemsElementName;

    public getCitizenFromLocalDbRequest() {
    }

    public getCitizenFromLocalDbDbRequest(object[] Items, GeneralServices.SomeService.ItemsChoiceType[] ItemsElementName) {
        this.Items = Items;
        this.ItemsElementName = ItemsElementName;
    }
}

现在为了解决这个问题,我将 getCitizenFromLocalDbRequest 更改如下,并从 references.cs 中删除了 ItemsChoiceType 枚举。是否有一些常见的不兼容问题导致这种行为?更重要的是,是否有一个体面的解决方法,而不是......这个?

public partial class getCitizenFromLocalDbRequest {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://somewhere.com/SomeService/Service/V4", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public long citizenId;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://somewhere.com/SomeService/Service/V4", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string name;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://somewhere.com/SomeService/Service/V4", Order=2)]
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string surname;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://somewhere.com/SomeService/Service/V4", Order=3)]
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="date")]
    public System.DateTime birthDate;


    public getCitizenFromLocalDbRequest() {
    }

    public getCitizenFromLocalDbRequest(long citizenId, string name, string surname,  System.DateTime birthDate) {
        this.citizenId = citizenId;
        this.name = name;
        this.surname = surname;
        this.birthDate = birthDate;
    }
}
4

0 回答 0