Почему GUID заменяется на строку при генерации прокси-класса для wsdl - PullRequest
0 голосов
/ 28 февраля 2020

У меня есть веб-сервис с параметрами типа GUID:

<xs:schema xmlns:ns1="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tns="http://schemas.datacontract.org/2004/07/TrafficApplicationServer.KP.Objects" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.datacontract.org/2004/07/TrafficApplicationServer.KP.Objects" attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
  <xs:element name="LtrDocumentObject" type="tns:LtrDocumentObject" nillable="true"/>
  <xs:complexType name="LtrDocumentObject">
    <xs:sequence>
      <xs:element name="UserGuid" type="ns1:guid" nillable="true" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

У сервиса есть определение GUID:

<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:element name="guid" type="tns:guid" nillable="true"/>
  <xs:simpleType name="guid">
    <xs:restriction base="xs:string">
      <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

Но когда я пытаюсь сгенерировать прокси-класс для этот wsdl в Visual Studio 2017 (. Net Framework 4.7.2) Тип GUID создается в виде строки:

/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(KpDocumentObject))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(TeoDocumentObject))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/TrafficApplicationServer.KP.Objects")]
public partial class LtrDocumentObject : object, System.ComponentModel.INotifyPropertyChanged {
    private string userGuidField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=48)]
    public string UserGuid {
        get {
            return this.userGuidField;
        }
        set {
            this.userGuidField = value;
            this.RaisePropertyChanged("UserGuid");
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}

Что мне нужно сделать, чтобы сгенерировать тип System.Guid?

1 Ответ

0 голосов
/ 28 февраля 2020

GUID преобразуются в строки для обеспечения совместимости sh.

Вы можете изменить тип обратно на Guid на стороне клиента, выполнив:

Guid myguid = new System.Guid(guidString);
...