我们有一个WCF的设置有以下合约:添加多个命名空间MessageContract WCF响应对象(MessageBodyMember)
[ServiceContract(
Namespace = Constants.Namespaces.HL7Namespace,
Name = Constants.Roles.ContentRequiredDocumentManagementSystem)]
// XmlSerializerFormat is needed to expose the HL7 schema fields without the "Field" suffix on each one, eg: idField
[XmlSerializerFormat]
public interface ICDARequest
{
[OperationContract(
// wsdl request action
Action = Constants.Namespaces.HL7Namespace + ":" + Constants.Interactions.RCMR_IN000029UV01 + "." + Constants.VersionType.NormativeCode + Constants.Version.InteractionVersion,
// wsdl operation name
Name = Constants.Interactions.RCMR_IN000029UV01,
// wsdl response action
ReplyAction = Constants.Namespaces.HL7Namespace + ":" + Constants.Interactions.RCMR_IN000030UV01 + "." + Constants.VersionType.NormativeCode + Constants.Version.InteractionVersion)]
SearchMessagesResponse SearchMessages(SearchMessagesRequest RCMR_IN000029UV01);
[MessageContract(
IsWrapped = false]
public class SearchMessagesResponse
{
[MessageBodyMember(
Name = State.Constants.Interactions.RCMR_IN000030UV01,
Namespace = State.Constants.Namespaces.HL7Namespace)]
public RCMR_IN000030UV01 data;
}
}
- 这些都是基于基于使用
xsd.exe
的HL7v3模式,它已经生成的类。 - 然后,我们改变了模式,使用自定义名称空间添加自定义元素,以区分它并重新生成类。
- 这工作得很好。
它补充说:
这是什么期望。
然后在WCF服务,我们能够使用新的类和成员:
var distStatus = new BCCDXDistributionStatus();
distStatus.receivedTime = CreateTS(locStat.MessageDownloadDate);
这个然后被序列化和送出通过线路看起来像:
<distributionStatus xmlns="urn:bccdx.ca">
<receivedTime value="201702150956-0800"/>
</distributionStatus>
这几乎是正确。这个麻烦来自XML文档没有提及"urn:bccdx.ca"
命名空间的事实。我假设它会在序列化时自动添加到文档根元素,但我错了。下面是该结束了看起来像:
<RCMR_IN000030UV01 ITSVersion="XML_1.0" xmlns="urn:hl7-org:v3">
...
</RCMR_IN000030UV01>
时候它真正需要的是一样的东西:
<RCMR_IN000030UV01 ITSVersion="XML_1.0" xmlns="urn:hl7-org:v3" xmlns:x="urn:bccdx.ca">
...
</RCMR_IN000030UV01>
注意瓮:bccdx.ca前缀
我想知道怎么样,如果可以的话,我们可以通过契约为结果的序列化消息XML添加多个名称空间和前缀?我已经看到了重写默认序列化器的提示,但我宁愿不要。当然这已经被认为和处理过?
1)有什么办法可以将它扩展到[mcve],或者至少是可以编译的东西,而不会丢失类型? 2)你说你使用'xsd.exe'来生成你的类,你在某处应用了'[XmlSerializerFormat]'吗?我没有看到它的问题。 – dbc
谢谢,是的,我编辑添加'XmlSerializerFormat'到原始问题。 – Bensonius