【问题标题】:WCF SOAP receive empty listWCF SOAP 接收空列表
【发布时间】:2015-10-23 12:46:13
【问题描述】:

我有一个 Android 应用程序和一个 WCF 服务来存储数据。我尝试使用 Android 应用程序(使用 kSOAP2)向服务发送请求。 一切正常,但是.. 当我尝试将列表(简单字符串或整数列表)发送到服务时,WCF 服务接收到消息但列表始终为空!

我的 SOAP 消息是这样的:

<MyList>
    <int>12</int>
    <int>50</int>
</MyList>

客户端或服务没有错误...但是列表总是空的,我不知道为什么。 有人知道 WCF 列表的正确格式吗?

提前致谢。

编辑:

我的服务界面:

[ServiceContract(Namespace = MyService.NamespaceV3)]
public interface IMyService
{
    [OperationContract]
    void MarkMessagesAsRead(List<int> ids, DateTime readDate, int employeeId);
}

参数readDate和employeeId工作正常,但是列表ids总是空的(不是null而是空的)。

编辑 2:

我的完整要求是:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    <v:Header />
    <v:Body>
        <MarkMessagesAsRead xmlns="http://schemas.xxx.fr/Mobile">
            <ids><int>10293</int><int>10295</int></ids>
            <readDate i:type="d:DateTime">2015-10-19T16:32:44.04</readDate>
            <employeeId i:type="d:int">18572</employeeId>
        </MarkMessagesAsRead>
    </v:Body>
</v:Envelope>

【问题讨论】:

  • 发布您的界面和 wcf 服务。它看起来像一个序列化/反序列化问题。在您的界面中,您的列表键入为 List ?
  • Yes 被键入为 List。我已经更新了我的帖子以添加界面。谢谢。
  • 我创建了一个具有相同接口的服务,并且工作的 xml 看起来像: 234 2015-10-23T13:00:000
  • 感谢您的帮助@RicardoPontual。我已经编辑了我的帖子以添加我的请求。与您的请求的不同之处在于最后两个参数的“i:type”。也许是命名空间的问题或缺少类型?

标签: c# android wcf soap ksoap2


【解决方案1】:

好的,我找到了解决方案:我只需将正确的命名空间添加到列表中的“int”元素即可。

用于数组和列表的命名空间是:http://schemas.microsoft.com/2003/10/Serialization/Arrays

【讨论】:

    猜你喜欢
    • 2021-08-21
    • 1970-01-01
    • 2013-12-21
    • 2018-11-22
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多