Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. SOAP Envelope - Passing parameters to WebService Method

SOAP Envelope - Passing parameters to WebService Method

Scheduled Pinned Locked Moved ASP.NET
wcfxmlcomhelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sumit Domyan
    wrote on last edited by
    #1

    Hi All I am looking for a solution to a problem regarding web service. I want to call a web method of a web service, but I don’t want to use wsdl nor can I generate the proxy class. The scenario is that, in my application user can fill in the web service address and a list of methods with parameters, he wants to execute and I have to get the results. I have some solution to this problem. Right now i am using WSE to solve this problem. My code is: Dim env As SoapEnvelope Dim epr As EndpointReference Dim client As MyHttpClient Dim rs As SoapEnvelope Dim bodyResponse As String env = New SoapEnvelope env.Context.Addressing.Action = New Action("http://tempuri.com/TestWebService/MyService/HelloWorld") env.CreateBody() env.Body.InnerXml = String.Format("{0}{1}", "Test", "User") epr = New EndpointReference(New Uri("http://localhost/TestWebService/MyService.asmx")) client = New MyHttpClient(epr) rs = client.Hello_World(env) bodyResponse = rs.Body.OuterXml TestReport.Text = bodyResponse Imports System.Xml Imports Microsoft.Web.Services2 Imports Microsoft.Web.Services2.Addressing Imports Microsoft.Web.Services2.Messaging Imports System.Web Public Class MyHttpClient Inherits SoapClient Public msg As String = String.Empty Public LoadTesterForm As LoadTesterForm = Nothing Public Sub New(ByVal dest As EndpointReference) MyBase.New(dest) End Sub _ Public Function Hello_World(ByVal envelope As SoapEnvelope) As SoapEnvelope Dim response As SoapEnvelope response = MyBase.SendRequestResponse("HelloWorld", envelope) msg = response.Body.OuterXml Hello_World = response End Function Protected Overrides Sub FilterMessage(ByVal envelope As Microsoft.Web.Services2.SoapEnvelope) MyBase.FilterMessage(envelope) End Sub End Class Web Service Method is: _ Public Function HelloWorld(ByVal first_name As String, ByVal last_name As String) As String Return "Hello " + first_name + " " + last_name + "!" End Function This code works fine, if there are no parameters accepted by web method HelloWorld. When i pass parameters, it returns the same result. Am i doing anything wrong while passing

    M 1 Reply Last reply
    0
    • S Sumit Domyan

      Hi All I am looking for a solution to a problem regarding web service. I want to call a web method of a web service, but I don’t want to use wsdl nor can I generate the proxy class. The scenario is that, in my application user can fill in the web service address and a list of methods with parameters, he wants to execute and I have to get the results. I have some solution to this problem. Right now i am using WSE to solve this problem. My code is: Dim env As SoapEnvelope Dim epr As EndpointReference Dim client As MyHttpClient Dim rs As SoapEnvelope Dim bodyResponse As String env = New SoapEnvelope env.Context.Addressing.Action = New Action("http://tempuri.com/TestWebService/MyService/HelloWorld") env.CreateBody() env.Body.InnerXml = String.Format("{0}{1}", "Test", "User") epr = New EndpointReference(New Uri("http://localhost/TestWebService/MyService.asmx")) client = New MyHttpClient(epr) rs = client.Hello_World(env) bodyResponse = rs.Body.OuterXml TestReport.Text = bodyResponse Imports System.Xml Imports Microsoft.Web.Services2 Imports Microsoft.Web.Services2.Addressing Imports Microsoft.Web.Services2.Messaging Imports System.Web Public Class MyHttpClient Inherits SoapClient Public msg As String = String.Empty Public LoadTesterForm As LoadTesterForm = Nothing Public Sub New(ByVal dest As EndpointReference) MyBase.New(dest) End Sub _ Public Function Hello_World(ByVal envelope As SoapEnvelope) As SoapEnvelope Dim response As SoapEnvelope response = MyBase.SendRequestResponse("HelloWorld", envelope) msg = response.Body.OuterXml Hello_World = response End Function Protected Overrides Sub FilterMessage(ByVal envelope As Microsoft.Web.Services2.SoapEnvelope) MyBase.FilterMessage(envelope) End Sub End Class Web Service Method is: _ Public Function HelloWorld(ByVal first_name As String, ByVal last_name As String) As String Return "Hello " + first_name + " " + last_name + "!" End Function This code works fine, if there are no parameters accepted by web method HelloWorld. When i pass parameters, it returns the same result. Am i doing anything wrong while passing

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, The namspace specified in the soap message body is not correct. The value of the xmlns attribute should look something like:

      http://tempuri.com/TestWebService/MyService/

      .

      S 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, The namspace specified in the soap message body is not correct. The value of the xmlns attribute should look something like:

        http://tempuri.com/TestWebService/MyService/

        .

        S Offline
        S Offline
        Sumit Domyan
        wrote on last edited by
        #3

        How can i set the namespace in the body? Sumit Domyan

        M 1 Reply Last reply
        0
        • S Sumit Domyan

          How can i set the namespace in the body? Sumit Domyan

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          ...
          env.Body.InnerXml = String.Format("<HelloWorld xmlns=""http://tempuri.com/TestWebService/MyService/""
          ...

          S 1 Reply Last reply
          0
          • M minhpc_bk

            ...
            env.Body.InnerXml = String.Format("<HelloWorld xmlns=""http://tempuri.com/TestWebService/MyService/""
            ...

            S Offline
            S Offline
            Sumit Domyan
            wrote on last edited by
            #5

            Hi Thanks a lot for your help, My application is working right now. Can you help me in maintaining session for a web service? My question is? How to maintain session for Web Services between SOAP requests? Thanks Sumit Domyan

            M 1 Reply Last reply
            0
            • S Sumit Domyan

              Hi Thanks a lot for your help, My application is working right now. Can you help me in maintaining session for a web service? My question is? How to maintain session for Web Services between SOAP requests? Thanks Sumit Domyan

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Javier just gave you the link which I was going to post.

              D 1 Reply Last reply
              0
              • M minhpc_bk

                Javier just gave you the link which I was going to post.

                D Offline
                D Offline
                domyansumit
                wrote on last edited by
                #7

                I am trying to implement it using SOAP Header, but not getting success. Might be i am not sending the proper SOAP Header. My SOAP Envelope looks like

                <soap:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                soap:Header
                <BeginSession xmlns="http://analec.com/TestWebService/MyService" mustUnderstand="1"></BeginSession>
                wsa:Actionhttp://analec.com/TestWebService/MyService/IncrementSessionCounterX</wsa:Action>
                wsa:MessageIDuuid:42816f56-d9e5-4dfc-8606-7fd788338d31</wsa:MessageID>
                wsa:ReplyTo
                wsa:Addresshttp://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
                </wsa:ReplyTo>
                wsa:Tohttp://localhost/TestWebService/MyService.asmx</wsa:To>
                wsse:Security
                <wsu:Timestamp wsu:Id="Timestamp-4378beed-f9ec-4cb3-982d-490dabd47f36">
                wsu:Created2005-06-21T12:55:14Z</wsu:Created>
                wsu:Expires2005-06-21T13:00:14Z</wsu:Expires>
                </wsu:Timestamp>
                </wsse:Security>
                </soap:Header>
                soap:Body
                <IncrementSessionCounterX xmlns="http://analec.com/TestWebService/MyService"></IncrementSessionCounterX>
                </soap:Body>
                </soap:Envelope>

                Everything is working fine, i am getting the response envelope back, but there is no header in the response envelope. Is there anything wrong with SOAP Header? Thanks Sumit

                M 1 Reply Last reply
                0
                • D domyansumit

                  I am trying to implement it using SOAP Header, but not getting success. Might be i am not sending the proper SOAP Header. My SOAP Envelope looks like

                  <soap:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                  soap:Header
                  <BeginSession xmlns="http://analec.com/TestWebService/MyService" mustUnderstand="1"></BeginSession>
                  wsa:Actionhttp://analec.com/TestWebService/MyService/IncrementSessionCounterX</wsa:Action>
                  wsa:MessageIDuuid:42816f56-d9e5-4dfc-8606-7fd788338d31</wsa:MessageID>
                  wsa:ReplyTo
                  wsa:Addresshttp://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
                  </wsa:ReplyTo>
                  wsa:Tohttp://localhost/TestWebService/MyService.asmx</wsa:To>
                  wsse:Security
                  <wsu:Timestamp wsu:Id="Timestamp-4378beed-f9ec-4cb3-982d-490dabd47f36">
                  wsu:Created2005-06-21T12:55:14Z</wsu:Created>
                  wsu:Expires2005-06-21T13:00:14Z</wsu:Expires>
                  </wsu:Timestamp>
                  </wsse:Security>
                  </soap:Header>
                  soap:Body
                  <IncrementSessionCounterX xmlns="http://analec.com/TestWebService/MyService"></IncrementSessionCounterX>
                  </soap:Body>
                  </soap:Envelope>

                  Everything is working fine, i am getting the response envelope back, but there is no header in the response envelope. Is there anything wrong with SOAP Header? Thanks Sumit

                  M Offline
                  M Offline
                  minhpc_bk
                  wrote on last edited by
                  #8

                  Hi there, By default, the Header element is not required to add to the response message. You can look at the schema of the envelope: http://schemas.xmlsoap.org/soap/envelope/[^] For more information, you can write a SoapExtension to trace/alter the response message. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconalteringsoapmessageusingsoapextensions.asp[^]

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups