问题标签 [datacontracts]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1022 浏览

c# - 遍历列表

我在遍历数据表并将每个值分配给数据合同列表中的给定属性时遇到了一些困难。

所以我有以下数据合同:

在我的服务中,我想返回一个 DispatchDetails 列表,但我的问题是为每个属性分配值。

我已经添加了我最新的狡猾的代码行来演示我想要完成的事情。我已经尝试了几种方法,但目前我似乎很难从树林中看到树林:)

提前感谢您提供的任何建议。

亲切的问候,克里斯蒂安

0 投票
1 回答
34 浏览

datacontracts - 如何从数据合约中的属性中获取属性名称

我有一个数据合同,我想获取下面代码中提到的属性名称。

现在我将值传递为

现在我需要传递而不是获取属性名称而不是硬编码的“电话号码”

我怎样才能做到这一点?

0 投票
2 回答
865 浏览

wcf - 如何在一个对象中继承三个数据契约?

如何调用三个数据合约对象并在单个对象中创建它?

我有一个像这样的数据合同类

另一个数据合同类,如

另一个数据合同类,如

现在我想以相同的方法使用 AddressId、EmailId、PhoneId。

怎么可能??

0 投票
2 回答
245 浏览

azure - Shared DataContract Worker 角色/Web 角色

我有一个 Azure Web 角色通过内部端点链接到工作角色,目的是使用工作角色向 Web 角色提供数据,保持 Web 角色和数据库 [包含敏感数据] 之间的隔离。有一个类库项目,其中包含工作角色和 Web 角色都引用的所有必要数据协定。

在开发环境中,一切都很好,而且效果很好。一旦我上传到 Azure,工作角色就无法启动。错误消息是:

它似乎无法打开数据协定类库“ReadOnly_DC”。

对 ReadOnly_DC 的引用设置为复制本地,我已尝试对与数据协定类库一起使用的所有引用“复制本地”,但无济于事。

任何建议都非常感谢!

授予

0 投票
2 回答
572 浏览

c# - 将数据访问层的值直接接受到数据合约中是否正确?

我有一个关于将从数据访问层中的数据库获得的值分配给 WCF 层的数据合同的正确方法的问题。

考虑一个简单的场景,从数据库中获取所有学生的列表,然后将其分配给学生数据合约。

我的学生数据合同如下所示:

在我的数据访问类中,我会有一个像 List GetAllStudents() 这样的方法

我的问题是关于我的 GetAllStudents() 方法的实现。它看起来像下面这样是否可以:

  1. 公共列表 GetAllStudents() {

    }

上述为数据合约赋值的方式是否正确,或者我应该让学生业务对象类接受数据访问层中的数据,然后在服务合约实现中将值传递给数据合约,如下所示:

  1. 我会有如下的学生业务对象类:

    公共课学生BO {

    }

在数据访问层中,我将从数据库中获取的值分配给学生业务对象的集合,如下所示:

然后,学生业务对象中的值将被分配给服务合同实现中的学生数据合同,从那里通过线路发送出去。

以上两种方式哪一种是正确的方式?

0 投票
1 回答
790 浏览

wcf - WCF 业务对象或数据合同

我有三个项目:

  • WCF 服务项目(接口和实现)
  • 使用 WCF 服务的 aspx Web 项目(客户端)
  • 包含我的业务对象的类库项目(由 WCF 项目和客户端共享)

我在 WCF 服务实现类文件中有一个方法,它从 SQL 中检索数据的通用列表(引用包含业务对象的项目),使用 System.Web.Script.Serialization.JavaScriptSerializer 序列化数据并将结果作为细绳。

Web 客户端获取此字符串并将其反序列化回适当的业务对象(引用保存业务对象的项目)

这是一个 Intranet 应用程序,我想确保我正确地执行此操作。

我的问题是:

  • 我应该使用 DataContracts 而不是业务对象吗?不确定何时使用 DataContracts 以及何时使用业务对象。
  • 如果我使用 DataContracts,我是否应该使用 System.Web.Script.Serialization.JavaScriptSerializer?

任何澄清将不胜感激。

0 投票
1 回答
867 浏览

wcf - WCF:数据成员的命名空间不同于父级

我们必须实现提供的外部 API。此 API 无法更改。对于此 API,交换 SOAP 消息,其中处理错误异常的消息如下所示:

虽然我们可以使用 asmx 等其他框架来实现这一点,但我们在 WCF 中没有成功:数据成员似乎与数据契约具有相同的命名空间。有没有办法为 datamember 添加命名空间?

非常感谢

0 投票
1 回答
171 浏览

c# - 为什么我的 JSON 在子数组上给我空值?

我一直在尝试让传入的 Json 消息进行序列化(并正确反序列化)。首先是我通过 POSTMAN 发布到我们的 MVC 休息服务的传入 Json。通过 JsonLint 对其进行验证。主要问题是两个子数组,accounts 和 propertyValues 作为空值传入。serviceAddresses 是 profilePush 的一个数组成员,它的其他属性正在填充。在我将它们全部放入 DataContracts 之前,我得到了 serviceAddresses 的空值。我在这里想念什么?

------------ 传入 JSON ------------------

--------这就是“配置文件”进入程序的样子--------------

0 投票
2 回答
2683 浏览

c# - List 类型的属性 in DataContract class fails

I'm developing a WCF with two Classes as DataContracts. One of them is a Data Structure developed by myself which manages Objects as JSON one, it names JSON; the other is ju

I'm developing a WCF with two Classes as DataContracts. One of them is a Data Structure developed by myself which manages Objects as JSON one, it names JSON; the other is just a Customized Object that my WebService recieve, it names Emission. I have three methods; one is for create policies, other one retrieves a policy and the last one consults catalogs in a dynamical way using JSON class. My problem comes within an error message like this:

"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter ... The InnerException message was 'Error in line 1 position 823. Element ... contains data of the 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfanyType' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.
Please see InnerException for more details."

I was looking for an answer then I noticed that the cause of my problem was a property in my JSON class which is a list of generic Objects. I need this property in my client to initialize the object I expect to recieve, so this list could contain strings or another List of Objects that's why I need this kind of item.

I've tried to use sort of KnownTypes with no success but I don't know if I'm doing something wrong

It is important to say that if I SET value property as internal everything goes fine even JSON class in client side although value property is never shown. Attach a shred of my code:

I hope you can really help me. Thanks in advice!


C++ function argument losing part of address

I got a really weird bug(?) on Win8x64 driver in C++, which crashes the system.

Background info: -- I did notice the driver crashes seemingly at random place of the codes, but didn't check why. - I'm making some changes in "funcD()", not related to the crash. - I compiled the binaries with debug, and noticed (now several time) that it crashes at the beginning of "funcB".

Problem: The issue is with the address of "arg2". The correct "arg2" address is there inside "funcA", which calls "funcB". But once inside "funcB", the address for "arg2" gets truncated.

e.g. arg2 = 0xffffe000'01ace148 while in "funcA", which then passes to calling "funcB". But inside "funcB", it becomes arg2 = 0x00000000'01ace148

I really have no idea how this can happen, so any suggestion welcomed! Don't think my changes in the downstream "funcD" could have caused this, yeah?

EDIT:

Both "typedefs" are pointer to some different structs.

Notice "funcA" doesn't do anything except calling "funcB" directly with the exact same arguments it receives. And both "funcA" and "funcB" have the same parameters (different return type tho), yet "funcA" has no problem receiving the arguments' addresses.

0 投票
1 回答
1151 浏览

wcf - 如何替换 Web Api 堆栈中的 DataContractResolver?

如果您使用 WCF,有很多不同的方法可以替换 DataContractResolver,我想用 Web Api 做同样的事情。我发现的唯一扩展点是:

我正在寻找(伪代码)行中的东西: