Yazılım vs. İnsan'ın ilk round'u,
Adamlar java axis servisi yazmış, c#'dan erişince patlıyor. Neden ki?
SomeService.SomeServiceV1x1Client client = new SomeService.SomeServiceV1x1Client ();
Serviste tanımlı client'ın client.InnerChannel'ına baktığımızda aşağıdaki hata geliyor.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.
şeklinde hata veriyorwsdl, referans falan derken bunun böyle farklı farklı bir saçmalık olduğu kanatine vardım.
Wsdl'da şöyle bir kısım var.
<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>
Görümüşe göre bu hatanın sebebi xsd:choice tag'ına c# generator'ların hassaslığı. Aşağıdaki gibi düzenlemelerle (tamamen choice elemanlarını uçurup alternatif çözümlerle) sorun çözülüyor ama ömrüm çürüdü valla. En doğrusu servis sağlayıcısının birşeyler yapması.
Benim çözüm yolum;
Wsdl'dan aşağıdaki reference kod parçaları generate ediliyor (tabii ki diğer ıvır zıvır'ın yanında).
[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 class'Inı aşağıdaki gibi yaparsak sorun çözülüyor.
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;
}
}
Bey,
Hiç yorum yok:
Yorum Gönder