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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 28, 2012, 1:10 AM EST
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.
Lal6 reputationPosted Mar 7, 2012, 9:30 AM EST
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