Encoding style

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Shirshov

    #1

    Encoding style

    Hello, All!

    I have the following webservice
    [vb]
    Imports System.Web.Serv ices
    Imports System.Xml

    <System.Web.Ser vices.WebServic e(Namespace:="h ttp://tempuri.org/WebApplication1/test"),
    Protocols.SoapD ocumentService( )> _
    Public Class test
    Inherits System.Web.Serv ices.WebService

    #Region " Web Services Designer Generated Code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Web Services Designer.
    InitializeCompo nent()

    'Add your own initialization code after the InitializeCompo nent()
    call

    End Sub

    'Required by the Web Services Designer
    Private components As System.Componen tModel.IContain er

    'NOTE: The following procedure is required by the Web Services Designer
    'It can be modified using the Web Services Designer.
    'Do not modify it using the code editor.
    <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
    InitializeCompo nent()
    components = New System.Componen tModel.Containe r
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    'CODEGEN: This procedure is required by the Web Services Designer
    'Do not modify it using the code editor.
    If disposing Then
    If Not (components Is Nothing) Then
    components.Disp ose()
    End If
    End If
    MyBase.Dispose( disposing)
    End Sub

    #End Region

    <WebMethod()> _
    Public Function HelloWorld() As CustomSerializa tion
    Return New CustomSerializa tion("Hello World")
    End Function

    Public Class CustomSerializa tion
    Implements Serialization.I XmlSerializable

    Private _str As String

    Public Sub New()
    _str = "default value"
    End Sub

    Public Sub New(ByVal str As String)
    _str = str
    End Sub

    Public Function GetSchema() As Schema.XmlSchem a Implements
    Serialization.I XmlSerializable .GetSchema
    Dim sr As New IO.StringReader ("<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefa ult='unqualifie d'
    id='test'><xs:e lement name='string' type='xs:string '/></xs:schema>")
    Dim xs As Schema.XmlSchem a = Schema.XmlSchem a.Read(sr, Nothing)
    sr.Close()
    Return xs
    End Function

    Public Sub ReadXml(ByVal reader As XmlReader) Implements
    Serialization.I XmlSerializable .ReadXml
    Throw New NotImplementedE xception
    End Sub

    Public Sub WriteXml(ByVal writer As XmlWriter) Implements
    Serialization.I XmlSerializable .WriteXml
    With writer
    .WriteElementSt ring("string", _str)
    End With
    End Sub
    End Class
    End Class
    [/vb]

    Here I have HelloWorld webmethod which returns instance of
    CustomSerializa tion class. CustomSerializa tion class is the simple class,
    except he is implementing IXmlSerializabl e. The class serializes into the
    following xml
    [xml]
    <string>Hello world</string>
    [/xml]

    What I want is to get exactly that xml in webservice response, i.e.
    [response]
    <soap:Body>
    <string>Hello World</string>
    </soap:Body>

    [/response]

    But I've got
    [actual-response]
    <soap:Body>
    <HelloWorldResu lt xmlns="http://tempuri.org/WebApplication1/test">
    <string>Hello World</string>
    </HelloWorldResul t>
    </soap:Body>
    [/actual-response]

    I don't want my xml is wrapped with HelloWorldResul t. I try to apply
    SoapDocumentMet hodAttribute with ParameterStyle= Bare and Use=Literal without
    success.

    So, the question is how to remove wrapping HelloWorldResul t element.

    With best regards, Alex Shirshov.


  • Sami Vaaraniemi

    #2
    Re: Encoding style

    Search Google Groups for "<soap:Body > with Two Unique Elements". This older
    thread has a solution that is probably applicable in your case too.

    Regards,
    Sami

    "Alex Shirshov" <nomail@mail.ru > wrote in message
    news:%23FqQdBza FHA.2736@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Hello, All!
    >
    > I have the following webservice
    > [vb]
    > Imports System.Web.Serv ices
    > Imports System.Xml
    >
    > <System.Web.Ser vices.WebServic e(Namespace:="h ttp://tempuri.org/WebApplication1/test"),
    > Protocols.SoapD ocumentService( )> _
    > Public Class test
    > Inherits System.Web.Serv ices.WebService
    >
    > #Region " Web Services Designer Generated Code "
    >
    > Public Sub New()
    > MyBase.New()
    >
    > 'This call is required by the Web Services Designer.
    > InitializeCompo nent()
    >
    > 'Add your own initialization code after the InitializeCompo nent()
    > call
    >
    > End Sub
    >
    > 'Required by the Web Services Designer
    > Private components As System.Componen tModel.IContain er
    >
    > 'NOTE: The following procedure is required by the Web Services Designer
    > 'It can be modified using the Web Services Designer.
    > 'Do not modify it using the code editor.
    > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
    > InitializeCompo nent()
    > components = New System.Componen tModel.Containe r
    > End Sub
    >
    > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    > 'CODEGEN: This procedure is required by the Web Services Designer
    > 'Do not modify it using the code editor.
    > If disposing Then
    > If Not (components Is Nothing) Then
    > components.Disp ose()
    > End If
    > End If
    > MyBase.Dispose( disposing)
    > End Sub
    >
    > #End Region
    >
    > <WebMethod()> _
    > Public Function HelloWorld() As CustomSerializa tion
    > Return New CustomSerializa tion("Hello World")
    > End Function
    >
    > Public Class CustomSerializa tion
    > Implements Serialization.I XmlSerializable
    >
    > Private _str As String
    >
    > Public Sub New()
    > _str = "default value"
    > End Sub
    >
    > Public Sub New(ByVal str As String)
    > _str = str
    > End Sub
    >
    > Public Function GetSchema() As Schema.XmlSchem a Implements
    > Serialization.I XmlSerializable .GetSchema
    > Dim sr As New IO.StringReader ("<xs:schema
    > xmlns:xs='http://www.w3.org/2001/XMLSchema'
    > elementFormDefa ult='unqualifie d' id='test'><xs:e lement name='string'
    > type='xs:string '/></xs:schema>")
    > Dim xs As Schema.XmlSchem a = Schema.XmlSchem a.Read(sr, Nothing)
    > sr.Close()
    > Return xs
    > End Function
    >
    > Public Sub ReadXml(ByVal reader As XmlReader) Implements
    > Serialization.I XmlSerializable .ReadXml
    > Throw New NotImplementedE xception
    > End Sub
    >
    > Public Sub WriteXml(ByVal writer As XmlWriter) Implements
    > Serialization.I XmlSerializable .WriteXml
    > With writer
    > .WriteElementSt ring("string", _str)
    > End With
    > End Sub
    > End Class
    > End Class
    > [/vb]
    >
    > Here I have HelloWorld webmethod which returns instance of
    > CustomSerializa tion class. CustomSerializa tion class is the simple class,
    > except he is implementing IXmlSerializabl e. The class serializes into the
    > following xml
    > [xml]
    > <string>Hello world</string>
    > [/xml]
    >
    > What I want is to get exactly that xml in webservice response, i.e.
    > [response]
    > <soap:Body>
    > <string>Hello World</string>
    > </soap:Body>
    >
    > [/response]
    >
    > But I've got
    > [actual-response]
    > <soap:Body>
    > <HelloWorldResu lt xmlns="http://tempuri.org/WebApplication1/test">
    > <string>Hello World</string>
    > </HelloWorldResul t>
    > </soap:Body>
    > [/actual-response]
    >
    > I don't want my xml is wrapped with HelloWorldResul t. I try to apply
    > SoapDocumentMet hodAttribute with ParameterStyle= Bare and Use=Literal
    > without success.
    >
    > So, the question is how to remove wrapping HelloWorldResul t element.
    >
    > With best regards, Alex Shirshov.
    >[/color]


    Comment

    • Sami Vaaraniemi

      #3
      Re: Encoding style

      Search Google Groups for "<soap:Body > with Two Unique Elements". This older
      thread has a solution that is probably applicable in your case too.

      Regards,
      Sami

      "Alex Shirshov" <nomail@mail.ru > wrote in message
      news:%23FqQdBza FHA.2736@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Hello, All!
      >
      > I have the following webservice
      > [vb]
      > Imports System.Web.Serv ices
      > Imports System.Xml
      >
      > <System.Web.Ser vices.WebServic e(Namespace:="h ttp://tempuri.org/WebApplication1/test"),
      > Protocols.SoapD ocumentService( )> _
      > Public Class test
      > Inherits System.Web.Serv ices.WebService
      >
      > #Region " Web Services Designer Generated Code "
      >
      > Public Sub New()
      > MyBase.New()
      >
      > 'This call is required by the Web Services Designer.
      > InitializeCompo nent()
      >
      > 'Add your own initialization code after the InitializeCompo nent()
      > call
      >
      > End Sub
      >
      > 'Required by the Web Services Designer
      > Private components As System.Componen tModel.IContain er
      >
      > 'NOTE: The following procedure is required by the Web Services Designer
      > 'It can be modified using the Web Services Designer.
      > 'Do not modify it using the code editor.
      > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
      > InitializeCompo nent()
      > components = New System.Componen tModel.Containe r
      > End Sub
      >
      > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      > 'CODEGEN: This procedure is required by the Web Services Designer
      > 'Do not modify it using the code editor.
      > If disposing Then
      > If Not (components Is Nothing) Then
      > components.Disp ose()
      > End If
      > End If
      > MyBase.Dispose( disposing)
      > End Sub
      >
      > #End Region
      >
      > <WebMethod()> _
      > Public Function HelloWorld() As CustomSerializa tion
      > Return New CustomSerializa tion("Hello World")
      > End Function
      >
      > Public Class CustomSerializa tion
      > Implements Serialization.I XmlSerializable
      >
      > Private _str As String
      >
      > Public Sub New()
      > _str = "default value"
      > End Sub
      >
      > Public Sub New(ByVal str As String)
      > _str = str
      > End Sub
      >
      > Public Function GetSchema() As Schema.XmlSchem a Implements
      > Serialization.I XmlSerializable .GetSchema
      > Dim sr As New IO.StringReader ("<xs:schema
      > xmlns:xs='http://www.w3.org/2001/XMLSchema'
      > elementFormDefa ult='unqualifie d' id='test'><xs:e lement name='string'
      > type='xs:string '/></xs:schema>")
      > Dim xs As Schema.XmlSchem a = Schema.XmlSchem a.Read(sr, Nothing)
      > sr.Close()
      > Return xs
      > End Function
      >
      > Public Sub ReadXml(ByVal reader As XmlReader) Implements
      > Serialization.I XmlSerializable .ReadXml
      > Throw New NotImplementedE xception
      > End Sub
      >
      > Public Sub WriteXml(ByVal writer As XmlWriter) Implements
      > Serialization.I XmlSerializable .WriteXml
      > With writer
      > .WriteElementSt ring("string", _str)
      > End With
      > End Sub
      > End Class
      > End Class
      > [/vb]
      >
      > Here I have HelloWorld webmethod which returns instance of
      > CustomSerializa tion class. CustomSerializa tion class is the simple class,
      > except he is implementing IXmlSerializabl e. The class serializes into the
      > following xml
      > [xml]
      > <string>Hello world</string>
      > [/xml]
      >
      > What I want is to get exactly that xml in webservice response, i.e.
      > [response]
      > <soap:Body>
      > <string>Hello World</string>
      > </soap:Body>
      >
      > [/response]
      >
      > But I've got
      > [actual-response]
      > <soap:Body>
      > <HelloWorldResu lt xmlns="http://tempuri.org/WebApplication1/test">
      > <string>Hello World</string>
      > </HelloWorldResul t>
      > </soap:Body>
      > [/actual-response]
      >
      > I don't want my xml is wrapped with HelloWorldResul t. I try to apply
      > SoapDocumentMet hodAttribute with ParameterStyle= Bare and Use=Literal
      > without success.
      >
      > So, the question is how to remove wrapping HelloWorldResul t element.
      >
      > With best regards, Alex Shirshov.
      >[/color]


      Comment

      • Alex Shirshov

        #4
        Re: Encoding style

        Hello, Sami!
        You wrote on Tue, 7 Jun 2005 11:18:45 +0300:

        [Sorry, skipped]

        Thank you, Sami! I think about to return XmlDocument or XmlNode from the
        method, but I cannot do this, 'cause ASP.NET will not generate proper wsdl.
        I thought ASP.NET supports message exchange pattern. Now, I see it's not.
        Only method calls in rpc style...

        With best regards, Alex Shirshov.


        Comment

        • Alex Shirshov

          #5
          Re: Encoding style

          Hello, Sami!
          You wrote on Tue, 7 Jun 2005 11:18:45 +0300:

          [Sorry, skipped]

          Thank you, Sami! I think about to return XmlDocument or XmlNode from the
          method, but I cannot do this, 'cause ASP.NET will not generate proper wsdl.
          I thought ASP.NET supports message exchange pattern. Now, I see it's not.
          Only method calls in rpc style...

          With best regards, Alex Shirshov.


          Comment

          Working...