从标题中删除某些由 WSE 3.0 创建的元素

发布于 2024-12-18 09:00:00 字数 1714 浏览 1 评论 0原文

我正在使用 wsdl,它会自动将额外的元素添加到 xml 中。为了使其符合不使用这些元素的外部 Web 服务。请参见下图: http://img406.imageshack.us/img406/1307/differencese.png 左 = 需要删除红色元素 - 右 = 我需要它输出什么,

我已附加了创建信封和有效负载的代码。

    Dim content As myProxy.Content = New myProxy.Content
    Dim inputguid As String = Guid.NewGuid.ToString
    Dim service As myProxy.WebService = New myProxy.WebService
    Dim str As New System.Xml.XmlDocument
    Dim payload As myProxy.Payload = New myProxy.Payload

    'payload
    str.LoadXml(xmlstr)

    'manifest
    service.payloadManifest = New myProxy.PayloadManifest
    service.payloadManifest.manifest = New myProxy.Manifest() {New myProxy.Manifest}
    service.payloadManifest.manifest(0).element = "GetVehicleServiceHistory"
    service.payloadManifest.manifest(0).namespaceURI = ""
    service.payloadManifest.manifest(0).contentID = "Content0"
    service.payloadManifest.manifest(0).version = "2.01"
    service.SoapVersion = SoapProtocolVersion.Soap11

    service.UserAgent = "Jakarta Commons-HttpClient/3.1"
    Dim usertoken As New Microsoft.Web.Services3.Security.Tokens.UsernameToken("userid", "password", Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendPlainText)

    service.RequestSoapContext.Security.Tokens.Add(usertoken)
    service.RequestSoapContext.Security.MustUnderstand = False

    payload.content = New myProxy.Content() {content}
    ReDim Preserve payload.content(0)
    payload.content(0).Any = str.DocumentElement
    payload.content(0).id = "Content0"

    service.Url = "http://localhost:8080"
    service.ProcessMessage(payload)

任何帮助将不胜感激。

迈克尔

I am working with a wsdl which is automatically adding extra elements into the xml. In order for it to comply with an external web service that do not use these elements. See the following image:
http://img406.imageshack.us/img406/1307/differencese.png
Left = Red elements need removed - Right = What i need it to output

i have attached the code that is creating my envelope and payload.

    Dim content As myProxy.Content = New myProxy.Content
    Dim inputguid As String = Guid.NewGuid.ToString
    Dim service As myProxy.WebService = New myProxy.WebService
    Dim str As New System.Xml.XmlDocument
    Dim payload As myProxy.Payload = New myProxy.Payload

    'payload
    str.LoadXml(xmlstr)

    'manifest
    service.payloadManifest = New myProxy.PayloadManifest
    service.payloadManifest.manifest = New myProxy.Manifest() {New myProxy.Manifest}
    service.payloadManifest.manifest(0).element = "GetVehicleServiceHistory"
    service.payloadManifest.manifest(0).namespaceURI = ""
    service.payloadManifest.manifest(0).contentID = "Content0"
    service.payloadManifest.manifest(0).version = "2.01"
    service.SoapVersion = SoapProtocolVersion.Soap11

    service.UserAgent = "Jakarta Commons-HttpClient/3.1"
    Dim usertoken As New Microsoft.Web.Services3.Security.Tokens.UsernameToken("userid", "password", Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendPlainText)

    service.RequestSoapContext.Security.Tokens.Add(usertoken)
    service.RequestSoapContext.Security.MustUnderstand = False

    payload.content = New myProxy.Content() {content}
    ReDim Preserve payload.content(0)
    payload.content(0).Any = str.DocumentElement
    payload.content(0).id = "Content0"

    service.Url = "http://localhost:8080"
    service.ProcessMessage(payload)

Any help would be much appreciated.

Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-12-25 09:00:00
    Dim content As blah.Content = New blah.Content
    Dim inputguid As String = Guid.NewGuid.ToString
    Dim service As blah.WebService = New blah.WebService
    Dim str As New System.Xml.XmlDocument
    Dim payload As blah.Payload = New blah.Payload

    'payload
    str.LoadXml(xmlstr)

    'manifest
    service.payloadManifest = New blah.PayloadManifest
    service.payloadManifest.manifest = New blah.Manifest() {New blah.Manifest}
    service.payloadManifest.manifest(0).element = "GetVehicleServiceHistory"
    service.payloadManifest.manifest(0).namespaceURI = ""
    service.payloadManifest.manifest(0).contentID = "Content0"
    service.payloadManifest.manifest(0).version = "2.01"
    service.SoapVersion = SoapProtocolVersion.Soap11

    service.UserAgent = "Jakarta Commons-HttpClient/3.1"


    payload.content = New blah.Content() {content}
    ReDim Preserve payload.content(0)
    payload.content(0).Any = str.DocumentElement
    payload.content(0).id = "Content0"

    service.ProcessMessage(payload)

注意到我已经删除了 WSE 编码:-

在 Web 参考 Reference.vb 中,我在 pcublic sub new 中添加了以下代码 -

        Dim policy As New Policy()
        policy.Assertions.Add(New MyAssertion())
        Me.SetPolicy(policy)

然后

Public Class MyPolicy
    Inherits SoapFilter
    Public Overrides Function ProcessMessage(ByVal envelope As SoapEnvelope) As SoapFilterResult
        'creating the <wsse:Security> element in the outgoing message
        Dim securityNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        Dim securityAttr As XmlAttribute = envelope.CreateAttribute("soap:mustunderstand")
        securityAttr.Value = "1"
        'creating the <wsse:usernameToken> element
        Dim usernameTokenNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        Dim userElement As XmlElement = usernameTokenNode
        userElement.SetAttribute("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")


        'creating the <wsse:Username> element
        Dim userNameNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        userNameNode.InnerXml = "username"


        'creating the <wsse:password> element
        Dim pwdNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:Password", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        Dim pwdElement As XmlElement = pwdNode
        pwdElement.SetAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText")
        pwdNode.InnerXml = "password"

        usernameTokenNode.AppendChild(userNameNode)
        usernameTokenNode.AppendChild(pwdNode)
        securityNode.AppendChild(usernameTokenNode)
        envelope.ImportNode(securityNode, True)
        Dim node As XmlNode = envelope.Header
        node.AppendChild(securityNode)


        Dim actionnode As XmlNode = envelope.Header("wsa:Action")
        envelope.Header.RemoveChild(actionnode)

        Dim messageNode As XmlNode = envelope.Header("wsa:MessageID")
        envelope.Header.RemoveChild(messageNode)

        Dim replyToNode As XmlNode = envelope.Header("wsa:ReplyTo")
        envelope.Header.RemoveChild(replyToNode)

        Dim toNode As XmlNode = envelope.Header("wsa:To")
        envelope.Header.RemoveChild(toNode)

        Return SoapFilterResult.[Continue]
    End Function
End Class

Public Class MyAssertion
    Inherits PolicyAssertion
    Public Overrides Function CreateClientInputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return Nothing
    End Function

    Public Overrides Function CreateClientOutputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return New MyPolicy()
    End Function

    Public Overrides Function CreateServiceInputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return Nothing
    End Function

    Public Overrides Function CreateServiceOutputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return Nothing
    End Function
End Class

公共覆盖函数 ProcessMessage - 覆盖 processmessage 并让我手动编辑

我需要的 信封手动删除我不需要的元素并手动插入我需要的元素:

    Dim content As blah.Content = New blah.Content
    Dim inputguid As String = Guid.NewGuid.ToString
    Dim service As blah.WebService = New blah.WebService
    Dim str As New System.Xml.XmlDocument
    Dim payload As blah.Payload = New blah.Payload

    'payload
    str.LoadXml(xmlstr)

    'manifest
    service.payloadManifest = New blah.PayloadManifest
    service.payloadManifest.manifest = New blah.Manifest() {New blah.Manifest}
    service.payloadManifest.manifest(0).element = "GetVehicleServiceHistory"
    service.payloadManifest.manifest(0).namespaceURI = ""
    service.payloadManifest.manifest(0).contentID = "Content0"
    service.payloadManifest.manifest(0).version = "2.01"
    service.SoapVersion = SoapProtocolVersion.Soap11

    service.UserAgent = "Jakarta Commons-HttpClient/3.1"


    payload.content = New blah.Content() {content}
    ReDim Preserve payload.content(0)
    payload.content(0).Any = str.DocumentElement
    payload.content(0).id = "Content0"

    service.ProcessMessage(payload)

noticed i've removed the WSE coding:-

within the web reference reference.vb i've added the following code in the pcublic sub new -

        Dim policy As New Policy()
        policy.Assertions.Add(New MyAssertion())
        Me.SetPolicy(policy)

and then

Public Class MyPolicy
    Inherits SoapFilter
    Public Overrides Function ProcessMessage(ByVal envelope As SoapEnvelope) As SoapFilterResult
        'creating the <wsse:Security> element in the outgoing message
        Dim securityNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        Dim securityAttr As XmlAttribute = envelope.CreateAttribute("soap:mustunderstand")
        securityAttr.Value = "1"
        'creating the <wsse:usernameToken> element
        Dim usernameTokenNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        Dim userElement As XmlElement = usernameTokenNode
        userElement.SetAttribute("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")


        'creating the <wsse:Username> element
        Dim userNameNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        userNameNode.InnerXml = "username"


        'creating the <wsse:password> element
        Dim pwdNode As XmlNode = envelope.CreateNode(XmlNodeType.Element, "wsse:Password", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        Dim pwdElement As XmlElement = pwdNode
        pwdElement.SetAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText")
        pwdNode.InnerXml = "password"

        usernameTokenNode.AppendChild(userNameNode)
        usernameTokenNode.AppendChild(pwdNode)
        securityNode.AppendChild(usernameTokenNode)
        envelope.ImportNode(securityNode, True)
        Dim node As XmlNode = envelope.Header
        node.AppendChild(securityNode)


        Dim actionnode As XmlNode = envelope.Header("wsa:Action")
        envelope.Header.RemoveChild(actionnode)

        Dim messageNode As XmlNode = envelope.Header("wsa:MessageID")
        envelope.Header.RemoveChild(messageNode)

        Dim replyToNode As XmlNode = envelope.Header("wsa:ReplyTo")
        envelope.Header.RemoveChild(replyToNode)

        Dim toNode As XmlNode = envelope.Header("wsa:To")
        envelope.Header.RemoveChild(toNode)

        Return SoapFilterResult.[Continue]
    End Function
End Class

Public Class MyAssertion
    Inherits PolicyAssertion
    Public Overrides Function CreateClientInputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return Nothing
    End Function

    Public Overrides Function CreateClientOutputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return New MyPolicy()
    End Function

    Public Overrides Function CreateServiceInputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return Nothing
    End Function

    Public Overrides Function CreateServiceOutputFilter(ByVal context As FilterCreationContext) As SoapFilter
        Return Nothing
    End Function
End Class

Public Overrides Function ProcessMessage - overwrites the processmessage and lets me manually edit the envelope

i needed to manually remove the elements i did not need and manually insert the elements Idid need:

日记撕了你也走了 2024-12-25 09:00:00

您可以编写一个 SoapExtension。我过去曾这样做过,以清除 SOAP 响应中的非法字符,但您也可以使用它来修改您的请求。基本上,它会在发送 SOAP 包之前或在您接收它时拦截 SOAP 包,但在 .Net 反序列化它之前。

Stefan Goßner 有一篇旧博客文章解释了 如何构建 SoapExtension。您可以将代码放入 ProcessOutput 方法中。

缺点是您将 SOAP 消息解析为文本,但如果效果更好的话,当然可以将其加载到 XDocumentXmlDocument 中。但之后您也会将其作为文本传递。

如果您使用的是 WCF,请查看在 WCF 客户端中拦截消息,因为您必须实现 IClientMessageInspector 来进行 SOAP 拦截。

希望这对您有所帮助。

You could write a SoapExtension. I've done this in the past to clean away illegal characters from a SOAP response, but you can use it to modify your request as well. Basically it will intercept the SOAP package before it's being sent, or when you receive it, but before .Net deserializes it.

Stefan Goßner has an old blog post which explains how build a SoapExtension. You would put your code inside the ProcessOutput method.

The drawback is that you are parsing the SOAP message as text, but can of course load it up in an XDocument or XmlDocument if that works better. But you are also passing it on as text afterwards.

If you are using WCF, then check out Intercept messages in a WCF Client, as you have to implement a IClientMessageInspector for the SOAP interception.

Hope this helps you a bit on the way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文