1

我们有一个 webserice,它接收带有如下所示肥皂头的 SOAP 消息......

以下 SOAP 消息正在发送到 Web 服务。但是,Web 服务无法将标头序列化到 MyMessageID 对象中

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       
xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
<soap:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">  
<wsa:To>https://www.xxx.co.uk/webservices/xxxxDEV/Service.asmx?  
op=TradesmanAllNBAt</wsa:To>  
<wsa:From>  
<Address>FromAddress</Address>  
</wsa:From>  
<wsa:ReplyTo>  
<Address>ReplyToAddress</Address>  
</wsa:ReplyTo>  
<wsa:Action>https://www.xxxx.co.uk/webservices/xxxxxDEV/TradesmanAllNBAt</wsa:Action>  
<wsa:MessageId>uuid:c6555fee-8b51-4664-88c8-74345b04dda5</wsa:MessageId>  
</soap:Header>  

Web服务的代码如下定义

    Imports System.Web.Services  
    Imports System.Web.Services.Protocols  
    Imports System.ComponentModel  
    Imports System.Xml  
    Imports Microsoft.Web.Services3  
    <System.Xml.Serialization.XmlRootAttribute(ElementName:="MessageId",  
    Namespace:="wsa", datatype:="string")> _  

    Public Class MessageId : Inherits SoapHeader  
        <System.Xml.Serialization.XmlTextAttribute()> _  
        Public TextValue As String  
    End Class  


    <System.Web.Services.WebService(Namespace:="https://www.xxxx.co.uk/webservices/xxxxDEV/")>   _    
    <ToolboxItem(False)> _  
    Public Class Service1  

        Inherits System.Web.Services.WebService  
        Public myMessageID As New MessageId  
        Public myRelatesTo As New RelatesTo  
        <WebMethod(), _  
            SoapHeader("myMessageID", Direction:=SoapHeaderDirection.InOut)>  
        Public Function TradesmanAllNBAt(ByVal objDocument As XmlDocument) As XmlDocument  

            Try  
                  myRelatesTo.TextValue = myMessageID.TextValue  


                Return (Nothing)  
            Catch ex As Exception  
                logError(ex.ToString)  
                Return Nothing  
            End Try  

        End Function  
    End Class  


The myMessageID object does not exists we accessing myMessageID.textvalue 

However, if I change the soap header and remove the name space as shown below

<soap:Header>

It works??  The third party insists on sending the name space in the soap header tag and I do not know how to resolve this issue.

Come on you SOAP gurus I really need help on this.

Many thanks in advance
4

1 回答 1

1

问题与序列化和名称空间有关,将 MessageID 类序列化更改为 System.Xml.Serialization.XmlRoot 并添加正确的命名空间

<System.Xml.Serialization.XmlRoot(ElementName:="MessageId", Namespace:="http://schemas.xmlsoap.org/ws/2004/03/addressing", datatype:="string")> _
Public Class MessageId : Inherits SoapHeader
    <System.Xml.Serialization.XmlTextAttribute()> _
    Public TextValue As String
End Class
于 2012-10-31T09:27:11.917 回答