SOAP Envelope - Passing parameters to WebService Method
-
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 -
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 passingHi 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/
.
-
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/
.
How can i set the namespace in the body? Sumit Domyan
-
How can i set the namespace in the body? Sumit Domyan
...
env.Body.InnerXml = String.Format("<HelloWorld xmlns=""http://tempuri.com/TestWebService/MyService/""
... -
...
env.Body.InnerXml = String.Format("<HelloWorld xmlns=""http://tempuri.com/TestWebService/MyService/""
...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
-
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
-
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
-
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
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[^]