質問

XMLに追加の要素を自動的に追加しているWSDLを使用しています。これらの要素を使用しない外部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)

どんな助けも大歓迎です。

マイケル

役に立ちましたか?

解決 2

    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 Reference.vb内で、Pcublic Sub New -new -new -new -new -oneに次のコードを追加しました。

        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-プロセスマセージを上書きし、エンベロープを手動で編集できます

必要のない要素を手動で削除し、ididが必要とする要素を手動で挿入する必要がありました。

他のヒント

あなたは書くことができます ソープテンション. 。過去にこれを行って、SOAP応答から違法なキャラクターをきれいにしていますが、それを使用してリクエストを変更することもできます。基本的には、Soapパッケージが送信される前、またはそれを受け取ったときに、しかし.NETがそれを降らない前に傍受します。

StefanGoßnerには、説明する古いブログ投稿があります ソープテンションの構築方法. 。コードを内側に配置します ProcessOutput 方法。

欠点は、あなたがテキストとして石鹸メッセージを解析しているが、もちろんにそれをロードすることができるということです XDocument また XmlDocument それがうまく機能する場合。しかし、あなたはそれをその後テキストとして伝えています。

WCFを使用している場合は、チェックアウトしてください WCFクライアントでメッセージを傍受します, 、aを実装する必要があるため IClientMessageInspector 石鹸傍受のため。

これがあなたを少し助けてくれることを願っています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top