0

I Have the following basicHttpBinding in my service config. When I consume this service any guids are serialised as strings. On closer inspection of the reference file i see that my classes and objects are being serialised with the system.xml.serialization not the datacontractserializer.

I have another service in the same project which shares the endpoint behaviours & configs and this service treats the guids as expected.

Any pointers greatly appreciated!

<service behaviorConfiguration="DefaultServiceBehaviour" name="ExtranetService.Repositories.Client.Submission.PSPSubmission.GoalRepository.GoalRepositoryService">
    <endpoint address="basic" 
              behaviorConfiguration="basicBehaviorConfig"
              binding="basicHttpBinding"
              bindingConfiguration="basicBindingConfig"
              name="basicEndpoint" 
              bindingName="basicBinding"
              contract="ExtranetService.Repositories.Client.Submission.PSPSubmission.GoalRepository.GoalRepositoryService"
              listenUriMode="Explicit" />
    <host>
        <baseAddresses>
            <add baseAddress="https://blah.com/Repositories/client/submission/pspsubmission/GoalRepositoryService.svc"/>
        </baseAddresses>
    </host>
</service>

<basicHttpBinding>
    <binding name="basicBindingConfig" 
             closeTimeout="00:05:00" 
             maxBufferPoolSize="2147483646" maxBufferSize="2147483646"
             maxReceivedMessageSize="2147483646">
       <readerQuotas maxDepth="32" 
                     maxStringContentLength="2147483646"
                     maxArrayLength="2147483646" />
       <security mode="Transport">
           <message clientCredentialType="Certificate" />
        </security>
    </binding>
</basicHttpBinding>

<serviceBehaviors>
    <behavior name="DefaultServiceBehaviour">
    <serviceMetadata />
    <serviceDebug />
        <dataContractSerializer />
    </behavior>
</serviceBehaviors>

<endpointBehaviors>
    <behavior name="basicBehaviorConfig">
        <dataContractSerializer />
    </behavior>
</endpointBehaviors>


<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234"),  _
System.SerializableAttribute(),  _
System.Diagnostics.DebuggerStepThroughAttribute(),  _
System.ComponentModel.DesignerCategoryAttribute("code"),  _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://schemas.datacontract.org/2004/07/ExtranetService.Repositories.Client.Submission.PSPSubmission.GoalRepository")>  _
Partial Public Class GetGoalByIdRequestObject
    Inherits Object
    Implements System.ComponentModel.INotifyPropertyChanged

    Private idField As String

    <System.Xml.Serialization.XmlElementAttribute(Order:=0)>  _
    Public Property Id() As String
        Get
            Return Me.idField
        End Get
        Set
            Me.idField = value
            Me.RaisePropertyChanged("Id")
        End Set
    End Property

    Public Event PropertyChanged As System.ComponentModel.PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Protected Sub RaisePropertyChanged(ByVal propertyName As String)
        Dim propertyChanged As System.ComponentModel.PropertyChangedEventHandler = Me.PropertyChangedEvent
        If (Not (propertyChanged) Is Nothing) Then
            propertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs(propertyName))
        End If
    End Sub
End Class

Edit

This is code from another service in the same project showing the guids as expected

<System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"),  _
 System.Runtime.Serialization.DataContractAttribute(Name:="GetClientRecommendationListRequestObject", [Namespace]:="http://schemas.datacontract.org/2004/07/ExtranetService.Repositories.Client.Submi"& _ 
    "ssion.PSPSubmission"),  _
 System.SerializableAttribute()>  _
Partial Public Class GetClientRecommendationListRequestObject
    Inherits Object
    Implements System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged

    <System.NonSerializedAttribute()>  _
    Private extensionDataField As System.Runtime.Serialization.ExtensionDataObject

    <System.Runtime.Serialization.OptionalFieldAttribute()>  _
    Private CLNT_CLIENT_IDField As System.Guid

    <Global.System.ComponentModel.BrowsableAttribute(false)>  _
    Public Property ExtensionData() As System.Runtime.Serialization.ExtensionDataObject Implements System.Runtime.Serialization.IExtensibleDataObject.ExtensionData
        Get
            Return Me.extensionDataField
        End Get
        Set
            Me.extensionDataField = value
        End Set
    End Property

    <System.Runtime.Serialization.DataMemberAttribute()>  _
    Public Property CLNT_CLIENT_ID() As System.Guid
        Get
            Return Me.CLNT_CLIENT_IDField
        End Get
        Set
            If (Me.CLNT_CLIENT_IDField.Equals(value) <> true) Then
                Me.CLNT_CLIENT_IDField = value
                Me.RaisePropertyChanged("CLNT_CLIENT_ID")
            End If
        End Set
    End Property

    Public Event PropertyChanged As System.ComponentModel.PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Protected Sub RaisePropertyChanged(ByVal propertyName As String)
        Dim propertyChanged As System.ComponentModel.PropertyChangedEventHandler = Me.PropertyChangedEvent
        If (Not (propertyChanged) Is Nothing) Then
            propertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs(propertyName))
        End If
    End Sub
End Class
Dooie
  • 1,649
  • 7
  • 30
  • 47
  • possible duplicate of [WCF - How to send GUIDs efficiently (not as strings)](http://stackoverflow.com/questions/4220135/wcf-how-to-send-guids-efficiently-not-as-strings) – Panagiotis Kanavos Jan 23 '15 at 09:01
  • I have seen this post but I do not have to do this with the other service in the project. – Dooie Jan 23 '15 at 09:05

1 Answers1

0

GUIDs aren't a valid XML data type so they can't be used as a member type in the XSD schema. No matter which serializer you use, if you want to use one of the Http bindings, GUIDs will be serialized as strings and defined as strings in the schema.

Any proxy generated from this schema will create a string-typed property because that's what the XSD defines.

The duplicate question shows how to pass the GUID as a byte array, although this will hurt interoperability.

Another option is to put all data contract classes in a separate library that is shared by both client and server code. The classes in the DTO assembly will be used when generating the proxy instead of creating new ones.

Another alternative is to add another property to the proxy DTO class eg IdAsGuid() that parses the string value and returns a GUID. All proxy classes are partial so you can add new properties without modifying the generated files

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236