unchase / Unchase.Odata.Connectedservice

:scroll: A Visual Studio extension for connecting to OData services with generating client-side C# proxy-classes
Apache License 2.0
44 stars 13 forks source link

Bug/Help wanted using StreamContent in OData v4 #54

Closed TripleNico closed 3 years ago

TripleNico commented 3 years ago

Currently i'am using a OData v4 third party server that uses Media object with OData. I automatically created the client code using the Unchase.Odata.Connectedservice Which runs fine but there are two things happening that seems to not work properly

  1. Namespace violation: For the use of StreamContent there is a entry added in the Metadata:
    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="System.Net.Http">
    <ComplexType Name="StreamContent">
        <Property Name="Headers" Type="Collection(System.Collections.Generic.KeyValuePair_2OfString_IEnumerable_1OfString)"/>
    </ComplexType>
    </Schema>

    That generates in this VB.NET code:

    Namespace System.Net.Http
    '''<summary>
    '''There are no comments for StreamContent in the schema.
    '''</summary>
    Partial Public Class StreamContent
        '''<summary>
        '''There are no comments for Property Headers in the schema.
        '''</summary>
        <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.7.0")>  _
        Public Property Headers() As Global.System.Collections.ObjectModel.Collection(Of System.Collections.Generic.KeyValuePair_2OfString_IEnumerable_1OfString)
            Get
                Return Me._Headers
            End Get
            Set
                Me.OnHeadersChanging(value)
                Me._Headers = value
                Me.OnHeadersChanged
            End Set
        End Property
        <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.7.0")>  _
        Private _Headers As Global.System.Collections.ObjectModel.Collection(Of System.Collections.Generic.KeyValuePair_2OfString_IEnumerable_1OfString) = New Global.System.Collections.ObjectModel.Collection(Of System.Collections.Generic.KeyValuePair_2OfString_IEnumerable_1OfString)()
        Partial Private Sub OnHeadersChanging(ByVal value As Global.System.Collections.ObjectModel.Collection(Of System.Collections.Generic.KeyValuePair_2OfString_IEnumerable_1OfString))
        End Sub
        Partial Private Sub OnHeadersChanged()
        End Sub
    End Class
    End Namespace

Now because the Namespace is called System.Net.Http it causes a namespace violation, breaking alot of this offcourse. So my question here, should it be an inherits/overload of the class System.Net.Http? Or how do i handle this?

  1. If i remove/ignore the above generated code and the solution use the default System.Net.Http Namespace then i get errors during serialisation:
    Execute, Message: An error occurred while processing this request.
    InnerExceptionMessage: The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom or JSON element or belongs to 'http://docs.oasis-open.org/odata/ns/data' namespace.

This is the response of the server:

{
  "@odata.context": "https://MyServer/odata/v1/$metadata#MediaFiles/ServerNamespace.Media.MediaFile",
  "value": [
    {
      "@odata.type": "#ServerNamespace.Media.MediaFile",
      "FolderId": 2,
      "Name": "MyImage.jpg",
      "Alt": null,
      "Title": null,
      "Extension": "jpg",
      "MimeType": "image/jpeg",
      "MediaType": "image",
      "Size": 30074,
      "PixelSize": 48400,
      "Metadata": null,
      "Width": 220,
      "Height": 220,
      "CreatedOnUtc": "2019-11-06T07:58:45.177Z",
      "UpdatedOnUtc": "2021-02-10T14:20:19.67Z",
      "IsTransient": false,
      "MediaStorageId": null,
      "Id": 2
    }
  ]
}
unchase commented 3 years ago

Hi, @TripleNico The VB code generation development has not evolved since I started contributing to OdataConnectedService. You can open the same issue in microsoft repository instead of this.

TripleNico commented 3 years ago

Sure, see #211