gpt4 book ai didi

.net - WCF 消息格式

转载 作者:行者123 更新时间:2023-12-01 23:49:36 24 4
gpt4 key购买 nike

我最近为客户重写了一个 WCF 服务。他们之前的服务是在 .NET 3.5 上,我清理了代码并升级到 4.5.2。

从功能上来说,该服务可以正常工作,但我遇到了消息格式某些方面不匹配的问题。

当我使用 WCF 服务客户端测试服务时,我收到一条具有以下结构的消息:

<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://XXXXX.com/XXXXX/service/v1_0/IXXXXXInterfacePort/GetRates</a:Action>
<a:MessageID>urn:uuid:071db031-f492-42f5-89e6-fb4a321c81c9</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetRatesIP xmlns="http://XXXXX.com/XXXXX/service/v1_0">
<ShipmentHeader xmlns="">
<ShipmentID>XXXXX</ShipmentID>
<Zipcode>XXXXX</Zipcode>
</ShipmentHeader>
<ShipmentItemsList xmlns="">
<ShipmentItems>
<quantity>10</quantity>
<sku>XXXXX</sku>
<freeShipping>true</freeShipping>
</ShipmentItems>
</ShipmentItemsList>
</GetRatesIP>
</s:Body>

但是当客户端将服务投入测试时,来自客户端的消息结构如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetRatesIP xmlns="http://XXXXX.com/XXXXX/service/v1_0">
<ShipmentHeader xmlns="">
<ShipmentID>XXXXX</ShipmentID>
<Zipcode>XXXXX</Zipcode>
</ShipmentHeader>
<ShipmentItemsList xmlns="">
<ShipmentItems>
<quantity>10</quantity>
<sku>XXXXX</sku>
</ShipmentItems>
</ShipmentItemsList>
</GetRatesIP>
</soap:Body>
</soap:Envelope>

从数据角度来看,一切似乎都正常。我的版本有免费送货属性,但据我所知,该服务将其视为可选,如果缺少,应该没问题。无论如何,客户端声称即使它在代码中,该值也从未被服务客户端发送过,即使在他们的代码中提到了它。

我的猜测是该服务在使用“soap:Envelope ...”样式与“s:Envelope ...”样式时遇到了问题。我使用了完全相同的服务契约(Contract)。现有代码使用 XML 序列化器而不是数据协定序列化器,但我再次从现有代码中准确复制了属性(Serialized、XmlType、XmlArray、XmlArrayItem 等)和 MessageContract 属性。查看了服务器上的配置,没有发现任何问题。致力于获取客户端配置,但不指望它能带来任何启发。

有人知道这里会发生什么吗?我一直(并将继续)在互联网上查找,但没有找到答案。我很幸运,它是在 Visual Studio/WCF 的碗中某处设置的一些奇怪的、晦涩的标志,只需要翻转它即可。

谢谢,詹姆斯

最佳答案

您的测试使用带有 WS-Addressing 的 SOAP 1.2 ( http://www.w3.org/2003/05/soap-envelope )( header 条目 a:Actiona:MessageID、 ...),而客户端使用 SOAP 1.1 ( http://schemas.xmlsoap.org/soap/envelope/ )。

这是一个具有约束力的问题。如果您希望客户端保持原样,请更改服务端的绑定(bind)。

关于.net - WCF 消息格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36359672/

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