Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 从标头中删除WSE 3.0创建的某些元素_.net_Xml_Soap_Wse3.0 - Fatal编程技术网

.net 从标头中删除WSE 3.0创建的某些元素

.net 从标头中删除WSE 3.0创建的某些元素,.net,xml,soap,wse3.0,.net,Xml,Soap,Wse3.0,我正在使用一个wsdl,它会自动向xml中添加额外的元素。以使其符合不使用这些元素的外部web服务。请参见下图: 左=需要删除红色元素-右=需要输出的内容 我已经附上了创建信封和有效载荷的代码 Dim content As myProxy.Content = New myProxy.Content Dim inputguid As String = Guid.NewGuid.ToString Dim service As myProxy.WebService = New

我正在使用一个wsdl,它会自动向xml中添加额外的元素。以使其符合不使用这些元素的外部web服务。请参见下图: 左=需要删除红色元素-右=需要输出的内容

我已经附上了创建信封和有效载荷的代码

    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)
任何帮助都将不胜感激

迈克尔

你可以写一封信。我过去这样做是为了清除SOAP响应中的非法字符,但是您也可以使用它来修改您的请求。基本上,它会在SOAP包被发送之前,或者在您收到它时,但在.Net反序列化它之前拦截它

Stefan Goßner有一篇老博文解释了这一点。您可以将代码放入
ProcessOutput
方法中

缺点是您将SOAP消息解析为文本,但如果效果更好,当然可以将其加载到
XDocument
XmlDocument
中。但你也在把它作为文本传递

如果您正在使用WCF,那么请退出,因为您必须为SOAP拦截实现
IClientMessageInspector

希望这对你有所帮助

    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
公共类MyPolicy
继承SoapFilter
Public将函数ProcessMessage(ByVal信封作为SoapEnvelope)重写为SoapFilterResult
'在传出消息中创建元素
Dim securityNode作为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”
'创建元素
Dim UsernameTokenode作为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作为XmlElement=usernameTokenNode
SetAttribute(“xmlns:wsu,”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
'创建元素
Dim userNameNode作为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=“用户名”
'创建元素
Dim pwdNode作为XmlNode=envelope.CreateNode(XmlNodeType.Element,“wsse:Password”,”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
尺寸pwdElement为xmlement=pwdNode
pwdElement.SetAttribute(“类型”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText")
pwdNode.InnerXml=“密码”
AppendChild(userNameNode)
usernameTokenNode.AppendChild(pwdNode)
AppendChild(usernameTokenNode)
envelope.ImportNode(securityNode,True)
作为XmlNode=envelope.Header的Dim节点
node.AppendChild(securityNode)
Dim actionnode作为XmlNode=envelope.Header(“wsa:Action”)
信封.Header.RemoveChild(actionnode)
Dim messageNode为XmlNode=envelope.Header(“wsa:MessageID”)
信封.Header.RemoveChild(messageNode)
Dim replyToNode为XmlNode=envelope.Header(“wsa:ReplyTo”)
信封.Header.RemoveChild(replyToNode)
Dim toNode为XmlNode=envelope.Header(“wsa:To”)
信封.Header.RemoveChild(toNode)
返回SoapFilterResult。[继续]
端函数
末级
公共类MyAssertion
继承策略断言
公共重写函数CreateClientInputFilter(ByVal上下文作为FilterCreationContext)作为SoapFilter
一无所获
端函数
公共重写函数CreateClientOutputFilter(ByVal上下文作为FilterCreationContext)作为SoapFilter
返回新的MyPolicy()
端函数
公共重写函数CreateServiceInputFilter(ByVal上下文作为FilterCreationContext)作为SoapFilter
一无所获
端函数
公共重写函数CreateServiceOutputFilter(ByVal上下文作为FilterCreationContext)作为SoapFilter
一无所获
端函数
末级
公共覆盖函数ProcessMessage-覆盖ProcessMessage并允许我手动编辑信封


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

这就是您要找的吗?