Hi All,
Please share some sample code for SOAP xml message passing and how to receive the message using WCF service and how to send the response to client , also how the client receive the soap xml messages from WCF services.
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
LalPosted Mar 7, 2012, 2:30 PM
Finally i got the correct answer. Please look into the below example how we can pass untyped message using SOAP xml.
Step 1 - WCF Service Code - Add Two Numbers
------------------------------------------------------
[ServiceContract]
public interface IService
{
[OperationContract(Action = "urn:my-add-request-com", ReplyAction = "urn:my-add-request-com", ProtectionLevel = ProtectionLevel.None)]
Message AddTwoNumbers(Message request);
}
public class Service : IService
{
public Message AddTwoNumbers(Message request)
{
XmlDictionaryReader rdr = request.GetReaderAtBodyContents();
int p1 = 0;
int p2 = 0;
while (rdr.Read())
{
if (rdr.LocalName == "p1")
{
p1 = rdr.ReadElementContentAsInt();
}
if (rdr.LocalName == "p2")
{
p2 = rdr.ReadElementContentAsInt();
}
}
int result = p1 + p2;
Message response = Message.CreateMessage(MessageVersion.Soap11, "urn:my-add-request-com", result);
return (response);
}
}
Step 2 - Client Proxy Code - Add Two Numbers
------------------------------------------------------
protected void Submit_Click(object sender, EventArgs e)
{
ServiceReference1.ServiceClient svc = new ServiceReference1.ServiceClient();
string requestString = "
StringReader stringReader = new StringReader(requestString);
XmlTextReader rdr = new XmlTextReader(stringReader);
Message request = Message.CreateMessage(MessageVersion.Soap11,"urn:my-add-request-com",rdr);
Message response = Message.CreateMessage(MessageVersion.Soap11, "urn:my-add-request-com");
response = svc.AddTwoNumbers(request);
Response.Write(response);
}
Please let me know if you have any query.
Thanks
Jignesh TrivediPosted Feb 28, 2012, 6:10 AM
please refer,
http://www.codeproject.com/Articles/11079/NET-XML-and-SOAP-Serialization-Samples-Tips
http://www.codeproject.com/Articles/38986/Trace-SOAP-Request-Response-XML-with-TraceExtensio
hope this help.