?
Solved

vb.net webservice soap consumer- print response xml

Posted on 2010-01-06
13
Medium Priority
?
1,872 Views
Last Modified: 2013-11-18
Hello - Well,
I've written a vb.net web service producer and a test consumer.
vs 2005

from the consumer side I have
myResponse = myService.RetrieveInquiryCreateRequest(myRequest)

I would like to - basically - print the response xml string ...
(actually fill a textbox with the xml string)

I can see the values in intellisense - i just want to grab the response's entire outerxml as a string ..?

I've really looked quite a bit out there and can't find much in reference to doing just this ...
0
Comment
Question by:chow_cheska
  • 8
  • 2
11 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 26195379
Can you tell me what kind of variable is myResponse?
Is it an XmlElement object?
and if you can post a screen shot of the intellisense values and what values are expecting on the string will be great
0
 

Author Comment

by:chow_cheska
ID: 26195525
ok -
the method:


<WebMethod()> _
    <Description("create a new inquiry investigation instance")> _
    Public Function RetrieveInquiryCreateRequest(ByVal request As InquiryCreateRequest) As InquiryCreateResponse
        Dim auth As New Authorize
        Dim granted As String = auth.check(request.RequestRecordAttributes.qts_service_key, request.RequestRecordAttributes.submitting_app_qtsid)
        If granted = "yes" Then
            Dim manager As New BusinessProcessManager()
            Return manager.RetrieveInquiryCreateRequest(request)
        Else
            Dim response As New InquiryCreateResponse()
            Dim responseattributes As New ResponseRecordAttributes
            responseattributes.systype = "fail"
            responseattributes.sysmessage = "Submitter Unauthorized"
            responseattributes.responseAction = request.ToString
            response.ResponseRecordAttributes = responseattributes
            Return response
        End If
    End Function

Open in new window

0
 

Author Comment

by:chow_cheska
ID: 26195533
and excerpt from the class
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082"),  _
     System.SerializableAttribute(),  _
     System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.ComponentModel.DesignerCategoryAttribute("code"),  _
     System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="http://qts.sebank.se/services/")>  _
    Partial Public Class RetrieveInquiryCreateRequestResponseRetrieveInquiryCreateRequestResult
        
        Private responseRecordAttributesField As RetrieveInquiryCreateRequestResponseRetrieveInquiryCreateRequestResultResponseRecordAttributes
        
        Private inquiryCreateResponseRecordField As RetrieveInquiryCreateRequestResponseRetrieveInquiryCreateRequestResultInquiryCreateResponseRecord
        
        '''<remarks/>
        Public Property ResponseRecordAttributes() As RetrieveInquiryCreateRequestResponseRetrieveInquiryCreateRequestResultResponseRecordAttributes
            Get
                Return Me.responseRecordAttributesField
            End Get
            Set
                Me.responseRecordAttributesField = value
            End Set
        End Property

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 36

Expert Comment

by:Miguel Oz
ID: 26195566
YOur response is a InquiryCreateResponse type.
Can I have excerpt from InquiryCreateResponse class?
And also what part of this class you want to recover as string.
0
 

Author Comment

by:chow_cheska
ID: 26195583
and the class itself:
Reference.vb
0
 

Author Comment

by:chow_cheska
ID: 26195611
didn't notice you had replied before mine ...
in essence there are 4 requests and 4 responses
i want to string out all the responses ...

each response has an attribures object and a record object (except ~list which has an item instead of record)

xml examples from the webservice:

SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /QTS/services/QtsService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://qts.sebank.se/services/RetrieveInquiryCreateRequest"

<?xml version="1.0" encoding="utf-8"?>
<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:Body>
    <RetrieveInquiryCreateRequest xmlns="http://qts.sebank.se/services/">
      <request>
        <RequestRecordAttributes qts_service_key="string" submitting_app_qtsid="string" requestAction="string" send_date="string" policy="string" config="string" />
        <InquiryCreateRecord>
          <country>bytes</country>
          <category>string</category>
          <type>string</type>
          <title>string</title>
          <comments>string</comments>
          <ext_clientpty_id>string</ext_clientpty_id>
          <ext_clientpty_name>string</ext_clientpty_name>
          <ext_user_id>string</ext_user_id>
          <ext_user_name>string</ext_user_name>
          <email>string</email>
          <phone_nr>string</phone_nr>
          <int_user_id>string</int_user_id>
        </InquiryCreateRecord>
      </request>
    </RetrieveInquiryCreateRequest>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<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:Body>
    <RetrieveInquiryCreateRequestResponse xmlns="http://qts.sebank.se/services/">
      <RetrieveInquiryCreateRequestResult>
        <ResponseRecordAttributes systype="string" sysmessage="string" responseAction="string" />
        <InquiryCreateResponseRecord>
          <qts_incident_id>string</qts_incident_id>
          <acknowledge>bytes</acknowledge>
        </InquiryCreateResponseRecord>
      </RetrieveInquiryCreateRequestResult>
    </RetrieveInquiryCreateRequestResponse>
  </soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.

POST /QTS/services/QtsService.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <RetrieveInquiryCreateRequest xmlns="http://qts.sebank.se/services/">
      <request>
        <RequestRecordAttributes qts_service_key="string" submitting_app_qtsid="string" requestAction="string" send_date="string" policy="string" config="string" />
        <InquiryCreateRecord>
          <country>bytes</country>
          <category>string</category>
          <type>string</type>
          <title>string</title>
          <comments>string</comments>
          <ext_clientpty_id>string</ext_clientpty_id>
          <ext_clientpty_name>string</ext_clientpty_name>
          <ext_user_id>string</ext_user_id>
          <ext_user_name>string</ext_user_name>
          <email>string</email>
          <phone_nr>string</phone_nr>
          <int_user_id>string</int_user_id>
        </InquiryCreateRecord>
      </request>
    </RetrieveInquiryCreateRequest>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <RetrieveInquiryCreateRequestResponse xmlns="http://qts.sebank.se/services/">
      <RetrieveInquiryCreateRequestResult>
        <ResponseRecordAttributes systype="string" sysmessage="string" responseAction="string" />
        <InquiryCreateResponseRecord>
          <qts_incident_id>string</qts_incident_id>
          <acknowledge>bytes</acknowledge>
        </InquiryCreateResponseRecord>
      </RetrieveInquiryCreateRequestResult>
    </RetrieveInquiryCreateRequestResponse>
  </soap12:Body>
</soap12:Envelope>

Open in new window

0
 

Author Comment

by:chow_cheska
ID: 26195628
the 'most complex' of the responses:
(~item has minoccur=0 and maxoccur=unbounded)
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<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:Body>
    <RetrieveIndividualUpdateListResponse xmlns="http://qts.sebank.se/services/">
      <RetrieveIndividualUpdateListResult>
        <ResponseRecordAttributes systype="string" sysmessage="string" responseAction="string" />
        <IndividualUpdateListResponseItem>
          <qts_incident_id>string</qts_incident_id>
          <qts_message_id>string</qts_message_id>
          <title>string</title>
          <log_date>string</log_date>
          <isOriginal>bytes</isOriginal>
          <direction>bytes</direction>
        </IndividualUpdateListResponseItem>
        <IndividualUpdateListResponseItem>
          <qts_incident_id>string</qts_incident_id>
          <qts_message_id>string</qts_message_id>
          <title>string</title>
          <log_date>string</log_date>
          <isOriginal>bytes</isOriginal>
          <direction>bytes</direction>
        </IndividualUpdateListResponseItem>
      </RetrieveIndividualUpdateListResult>
    </RetrieveIndividualUpdateListResponse>
  </soap:Body>
</soap:Envelope>

Open in new window

0
 

Author Comment

by:chow_cheska
ID: 26197468
i can't seem to screen capture the intellisense ... you have a trick to do that?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 26306006
I think what you are looking for is the SoapExtension class:

SoapExtension Class
http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapextension(VS.80).aspx

The following TraceExtension SOAP extension outputs the SOAP request and SOAP response to a specified file when applied to an XML Web service method. If the following SOAP extension is installed to run with an XML Web service, the ASPNET user account must have permission to write to the directory in which the log file is written.


Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.IO

' Define a SOAP Extension that traces the SOAP request and SOAP response
' for the XML Web service method the SOAP extension is applied to.
Public Class TraceExtension
    Inherits SoapExtension

    Private oldStream As Stream
    Private newStream As Stream
    Private m_filename As String

    ' Save the Stream representing the SOAP request or SOAP response into
    ' a local memory buffer.
    Public Overrides Function ChainStream(ByVal stream As Stream) As Stream
        oldStream = stream
        newStream = New MemoryStream()
        Return newStream
    End Function

    ' When the SOAP extension is accessed for the first time, the XML Web
    ' service method it is applied to is accessed to store the file
    ' name passed in, using the corresponding SoapExtensionAttribute.    
    Public Overloads Overrides Function GetInitializer(ByVal methodInfo As _
        LogicalMethodInfo, _
    ByVal attribute As SoapExtensionAttribute) As Object
        Return CType(attribute, TraceExtensionAttribute).Filename
    End Function

    ' The SOAP extension was configured to run using a configuration file
    ' instead of an attribute applied to a specific XML Web service
    ' method.  Return a file name based on the class implementing the Web
    ' Service's type.
    Public Overloads Overrides Function GetInitializer(ByVal WebServiceType As _
      Type) As Object
        ' Return a file name to log the trace information to, based on the
        ' type.
        Return "C:\" + WebServiceType.FullName + ".log"
    End Function

    ' Receive the file name stored by GetInitializer and store it in a
    ' member variable for this specific instance.
    Public Overrides Sub Initialize(ByVal initializer As Object)
        m_filename = CStr(initializer)
    End Sub

    ' If the SoapMessageStage is such that the SoapRequest or SoapResponse
    ' is still in the SOAP format to be sent or received over the network,
    ' save it out to file.
    Public Overrides Sub ProcessMessage(ByVal message As SoapMessage)
        Select Case message.Stage
            Case SoapMessageStage.BeforeSerialize
            Case SoapMessageStage.AfterSerialize
                WriteOutput(message)
            Case SoapMessageStage.BeforeDeserialize
                WriteInput(message)
            Case SoapMessageStage.AfterDeserialize
            Case Else
                Throw New Exception("invalid stage")
        End Select
    End Sub

    ' Write the SOAP message out to a file.
    Public Sub WriteOutput(ByVal message As SoapMessage)
        newStream.Position = 0
        Dim fs As New FileStream(m_filename, FileMode.Append, _
                                 FileAccess.Write)
        Dim w As New StreamWriter(fs)
        w.WriteLine("-----Response at " + DateTime.Now.ToString())
        w.Flush()
        Copy(newStream, fs)
        w.Close()
        newStream.Position = 0
        Copy(newStream, oldStream)
    End Sub

    ' Write the SOAP message out to a file.
    Public Sub WriteInput(ByVal message As SoapMessage)
        Copy(oldStream, newStream)
        Dim fs As New FileStream(m_filename, FileMode.Append, _
                                 FileAccess.Write)
        Dim w As New StreamWriter(fs)

        w.WriteLine("----- Request at " + DateTime.Now.ToString())
        w.Flush()
        newStream.Position = 0
        Copy(newStream, fs)
        w.Close()
        newStream.Position = 0
    End Sub

    Sub Copy(ByVal fromStream As Stream, ByVal toStream As Stream)
        Dim reader As New StreamReader(fromStream)
        Dim writer As New StreamWriter(toStream)
        writer.WriteLine(reader.ReadToEnd())
        writer.Flush()
    End Sub
End Class

' Create a SoapExtensionAttribute for our SOAP Extension that can be
' applied to an XML Web service method.
<AttributeUsage(AttributeTargets.Method)> _
Public Class TraceExtensionAttribute
    Inherits SoapExtensionAttribute

    Private m_filename As String = "c:\log.txt"
    Private m_priority As Integer

    Public Overrides ReadOnly Property ExtensionType() As Type
        Get
            Return GetType(TraceExtension)
        End Get
    End Property

    Public Overrides Property Priority() As Integer
        Get
            Return m_priority
        End Get
        Set(ByVal Value As Integer)
            m_priority = value
        End Set
    End Property

    Public Property Filename() As String
        Get
            Return m_filename
        End Get
        Set(ByVal Value As String)
            m_filename = value
        End Set
    End Property
End Class

Open in new window

0
 

Author Comment

by:chow_cheska
ID: 26320769
thanx LearnedOne!

I do very much appreciate it!

it makes it so much easier to trace and debug with the consumer team when you can see what the result actually is ...

/Nick
0
 

Author Closing Comment

by:chow_cheska
ID: 31673709
thanx!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question