我们需要打电话给SOAP服务。
不幸的是,WSDL生成的代码不能像预期的那样工作,因为它们需要MTOM哪个causes problems we have not been able to resolve。因此,我们被迫重新发明车轮,我试图找出最好的(或至少是一个好的方法)来做到这一点。
SOAP服务将创建如下响应:
--uuid:d49971de-e2c2-4af4-947d-c0acc0f6ad64
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
Content-Transfer-Encoding: binary
Content-ID:
<root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns2:listAttachmentsResponse xmlns:ns2="http://ws.praxedo.com/v6/businessEvent">
<return>
<resultCode>0</resultCode>
<entities>
<entityId>00044</entityId>
<name>JohnDoe.pdf</name>
<addedOnDevice>false</addedOnDevice>
<creationDate>2021-03-17T20:48:36.849+01:00</creationDate>
<external>false</external>
<id>1103057659_1500033662_C_05126a814b440b8c6efea0d195cbae8f</id>
<lastModificationDate>2021-05-04T20:38:42.829+02:00</lastModificationDate>
<size>249794</size>
<unmodifiable>false</unmodifiable>
</entities>
<entities>
<entityId>00044</entityId>
<name>OAY3PD.pdf</name>
<addedOnDevice>false</addedOnDevice>
<creationDate>2021-03-17T20:48:36.829+01:00</creationDate>
<external>false</external>
<id>1103057659_1500033662_C_04870c813b0c352bed5213425a946d5c</id>
<lastModificationDate>2021-05-04T20:38:42.829+02:00</lastModificationDate>
<size>465275</size>
<unmodifiable>false</unmodifiable>
</entities>
</return>
</ns2:listAttachmentsResponse>
</soap:Body>
</soap:Envelope>
--uuid:d49971de-e2c2-4af4-947d-c0acc0f6ad64--我希望结果是一个POCO,可能是这样的:
public class ListAttachmentsResponse {
public int ResultCode { get; init; }
public Attachment[] Attachments
}
public class Attachment {
// This is the "entityId", we need to keep the leading zeros.
public string BusinessEventId { get; init; }
public string FileName { get; init; }
public bool IsAddedOnDevice { get; init; }
public DateTime CreationDate { get; init; }
public bool IsExternal { get; init; }
public string Id { get; init; }
public DateTime LastModificationDate { get; init; }
public int size { get; init; }
public bool IsUnmodifiable { get; init ;}
}..。但是如果其他的东西更容易检索的话,我可以灵活地处理这个结构。
发布于 2021-09-21 16:02:26
在使用一些示例数据使用Visual的“粘贴特殊->粘贴Xml作为类”之后,我能够获得以下方法:
private const string EnvelopeClose = "</soap:Envelope>";
private static listAttachmentsResponse Parse(string responseContent)
{
string data = responseContent[responseContent.IndexOf("<soap:Envelope")..];
int envelopeCloseIndex = data.IndexOf(EnvelopeClose);
data = data.Substring(0, envelopeCloseIndex) + EnvelopeClose;
XmlSerializer serializer = new(typeof(ResponseEnvelope));
ResponseEnvelope result;
using (StringReader reader = new(data))
{
result = (ResponseEnvelope)serializer.Deserialize(reader);
}
return result.Body.listAttachmentsResponse;
}我认为这是非常丑陋的,所以我愿意接受更好的方法来做这件事!
https://stackoverflow.com/questions/69270797
复制相似问题