• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 793
  • Last Modified:

How do I write the WebMethod() to generate the "The SOAP response" like below ?

I am having trouble writing a SOAP response.

I can write the SOAP WebMethod, which looks like the "A SOAP request" indicated below.
<WebMethod()> _
    Public Function GetStockPrice(StockName As String) As String
        Return "<m:Price>34.5</m:Price>"
    End Function

I don't know how to write the WebMethod() to generate this...
<m:Price>34.5</m:Price>


---> How do I write the WebMethod() to generate the "The SOAP response" like below ?


Reference:
http://www.w3schools.com/soap/soap_example.asp


A SOAP request:
POST /InStock HTTP/1.1
 Host: www.example.org
 Content-Type: application/soap+xml; charset=utf-8
 Content-Length: nnn
 <?xml version="1.0"?>
 <soap:Envelope
 xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
 soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
 <soap:Body xmlns:m="http://www.example.org/stock">
   <m:GetStockPrice>
     <m:StockName>IBM</m:StockName>
   </m:GetStockPrice>
 </soap:Body>
 </soap:Envelope>


The SOAP response:
HTTP/1.1 200 OK
 Content-Type: application/soap+xml; charset=utf-8
 Content-Length: nnn
 <?xml version="1.0"?>
 <soap:Envelope
 xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
 soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
   <m:GetStockPriceResponse>
       <m:Price>34.5</m:Price>
   </m:GetStockPriceResponse>
 </soap:Body
 </soap:Envelope>


---- end ---
0
MikeCombe
Asked:
MikeCombe
1 Solution
 
Rose BabuSenior Team ManagerCommented:
Hi,

here is the sample webservice code for the the xml request and response structure you wanted. check this

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://www.domaintest.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
    Inherits System.Web.Services.WebService

    Class GetStockPriceDetails
        Private PriceField As String

        Public Property Price() As String
            Get
                Return PriceField
            End Get
            Set(ByVal value As String)
                PriceField = value
            End Set
        End Property
    End Class

    <WebMethod()> _
    Public Function GetStockPrice(ByVal StockName As String) As GetStockPriceDetails
        Dim resp As New GetStockPriceDetails
        resp.Price = "34.5"
        Return resp
    End Function

End Class

Open in new window

Soap XML request and response structures

' Request
<?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>
    <GetStockPrice xmlns="http://www.domaintest.org/">
      <StockName>string</StockName>
    </GetStockPrice>
  </soap:Body>
</soap:Envelope>

' Response
<?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>
    <GetStockPriceResponse xmlns="http://www.domaintest.org/">
      <GetStockPriceResult>
        <Price>string</Price>
      </GetStockPriceResult>
    </GetStockPriceResponse>
  </soap:Body>
</soap:Envelope>

Open in new window

0
 
MikeCombeAuthor Commented:
perfect !
thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now