无法创建SOAP标头对象

时间:2012-10-30 10:09:20

标签: .net web-services soap wse3.0

我们有一个webserice,它使用soap标头重新接收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

1 个答案:

答案 0 :(得分: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