gpt4 book ai didi

java - 将 SOAP 响应反序列化到生成的类 C#

转载 作者:行者123 更新时间:2023-11-30 02:45:39 24 4
gpt4 key购买 nike

我们正在与第三方集成,但在反序列化从请求中获得的响应时遇到问题。从 fiddler 中,我可以看到响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>
<ns2:updateItemsResponse xmlns:ns2="http://ThirdParty/dmn/items/1.1">
<fileId>bd6e7d83-8bfu-4573-fe32-c67c04355dd0</fileId>
<fileName>12345.MBG_Items.002.2016-10-26-16-23-35.xml</fileName>
</ns2:updateItemsResponse>

但是我们无法将其正确反序列化为 updateItemsResponse 对象。对象已创建,但 fileId 和 fileName 均为 null。我们为此请求和响应生成了类,下面是生成的类:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName = "updateItemsResponse", WrapperNamespace = "http://ThirdParty/dmn/items/1.1", IsWrapped = true)]
public partial class updateItemsResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://ThirdParty/dmn/items/1.1", Order = 0)]
public string fileName;

[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://ThirdParty/dmn/items/1.1", Order = 1)]
public string fileId;

public updateItemsResponse()
{
}

public updateItemsResponse(string fileId, string fileName)
{
this.fileId= fileId;
this.fileName= fileName;
}
}

我们知道 Web 服务是用 Java 编写的,并且在生成类文件时遇到了一些问题 - 在我们能够使用 svcutil.exe 创建类文件之前,我们提供的 wsdl 需要一些技巧。所以我认为我需要在生成的文件中进行一些调整。

我已经对此进行了一些搜索,我猜测这里的问题是命名空间,但我无法让它工作。我尝试过更改命名空间、删除命名空间、更改 fileId 和 fileName 的顺序 - 但这些都没有产生任何区别。

有人能看到我可能遗漏的任何明显的东西吗?这让我发疯了!!!

编辑:也尝试过将 fileId 和 fileName 更改为 XmlElement,但仍然得到空响应。

最佳答案

Eureka !!!

所以这是错误的属性 - fileId 和 fileName。只需将它们更改为

[System.ServiceModel.MessageBodyMemberAttribute(Name = "fileId", Namespace = "", Order = 0)]
public string fileId;

[System.ServiceModel.MessageBodyMemberAttribute(Name = "fileName", Namespace = "", Order = 1)]
public string fileName;

我现在可以反序列化响应。

关于java - 将 SOAP 响应反序列化到生成的类 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40284131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com