在 OData v4 中使用 StreamContent

问题描述

目前我正在使用 OData v4 第三方服务器,该服务器将 Media 对象与 OData 结合使用。我使用运行正常的 set filePath to (path to desktop as text) & "test.m4a" delay 1 tell application "QuickTime Player" activate set new_recording to (new audio recording) tell new_recording start delay 5 stop end tell open for access file filePath close access file filePath export (first document) in filePath using settings preset "Audio Only" close (first document) without saving ignoring application responses quit end ignoring end tell 自动创建了客户端代码,但有两件事似乎无法正常工作

  1. 命名空间违规:为了使用 StreamContent,在元数据中添加一个条目:
Odata.Connectedservice

在此 VB.NET 代码生成

<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>

现在因为命名空间被称为 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 ,它会导致命名空间违规,破坏了很多这种偏离。所以我的问题是,它应该是类 System.Net.Http 的继承/重载吗?或者我该如何处理?

  1. 如果我删除/忽略上面生成代码并且解决方案使用认的 System.Net.Http 命名空间,那么我在序列化过程中会出错:
System.Net.Http

这是服务器的响应:

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.

响应头:

{
  "@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
    }
  ]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)