我正在尝试通过SOAP请求提交数据。 Web服务中接收的数据为空,可能是因为我发送的XML中的空白xmlns命名空间导致数据返回null(例如TransmissionVersion)。大多数在线资源建议删除xmlns =“”,但是有一种快速的方法可以使服务接受命名空间而不必检查它并在发送请求之前删除它,就像在这里一样吗?
https://cmatskas.com/changing-soap-message-data-and-namespaces-with-c/
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:efil="http://samplelink.org" xmlns="http://samplelink.org">
<soapenv:Header/>
<soapenv:Body>
<Send xmlns="http://samplelink.org">
<Transmission>
<SimplifiedReturnTransmission transmissionVersion="2015V01" xmlns="">
<TransmissionHeader>
<TransmissionId>TI000024691218803</TransmissionId>
<Timestamp>2014-09-07T10:18:26</Timestamp>
<Transmitter>
<ETIN>67666665</ETIN>
</Transmitter>
<ProcessType>T</ProcessType>
<DocumentCount>1</DocumentCount>
<TransmissionPaymentHash>14022.49</TransmissionPaymentHash>
</TransmissionHeader>
</SimplifiedReturnTransmission>
</Transmission>
</Send>
</soapenv:Body>
</soapenv:Envelope>
以下是界面中的相关代码:
<DataContract()>
<System.Xml.Serialization.XmlRootAttribute("SimplifiedReturnTransmission")>
Public Class SimplifiedReturnTransmissionType
Private transmissionHeaderField As TransmissionHeaderType
Private simplifiedReturnDocumentField() As SimplifiedReturnDocumentType
Private transmissionVersionField As String
<DataMember(EmitDefaultValue:=False)>
<System.Xml.Serialization.XmlElementAttribute("TransmissionHeader")>
Public Property TransmissionHeader() As TransmissionHeaderType
Get
Return Me.transmissionHeaderField
End Get
Set(ByVal value As TransmissionHeaderType)
Me.transmissionHeaderField = value
End Set
End Property
<DataMember(EmitDefaultValue:=False)> <System.Xml.Serialization.XmlAttributeAttribute()>
Public Property transmissionVersion() As String
Get
Return Me.transmissionVersionField
End Get
Set(ByVal value As String)
Me.transmissionVersionField = value
End Set
End Property
End Class
答案 0 :(得分:0)
使元素具有空白名称空间,而ElementAttribute而不是RootAttribute解决了该问题。该元素的父元素变为根属性。
<System.Xml.Serialization.XmlElementAttribute("SimplifiedReturnTransmission")>
<System.Xml.Serialization.XmlRootAttribute("Transmission", [Namespace]:="", IsNullable:=False)>