C# expert - quick help
Budget: $10 – $30 USD
Replace the Message (System.ServiceModel.Channels) content with altered soap xml. If any xml element of SOAP message in the "ref Message reply" paramte has a value of "0E-number" eg: 0E-7 then replace it with 0 and update the "ref Message reply" paramter, You should retain the same xml format. Just replace only those values if found.
See the attached code
/// <summary>
/// Allows adding in WS-Security header to incoming request
/// </summary>
public class TestMessageInspector : IClientMessageInspector
{
.......
public void AfterReceiveReply(ref Message reply, object correlationState)
{
// Here Need to replace or alter the reply Message (System.ServiceModel.Channels) content with other soap xml. Tried the below code and it does not alter the reply message content
var sb = new StringBuilder("<testAmt>88977</testAmt>");
using (var sw = XmlWriter.Create(new StringWriter(sb)))
{
reply.WriteMessage(sw);
sw.Flush();
} }
}
Sample Input:
<? xml version='1.0' encoding='utf-16'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'><SOAP-ENV:Header/><SOAP-ENV:Body>< ns4:testResponse xmlns:ns2 = 'http://www.seconddecimal.com/ncsts/schemas/unrestricted/messages' xmlns:ns4 ='http://www.seconddecimal.com/ncsts/schemas/messages'><Document><testAmt >0E-7</testAmt><testRate>0</testRate><test1Amt>0E-8</test1Amt></Document></ns4:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Sample Output:
<? xml version='1.0' encoding='utf-16'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'><SOAP-ENV:Header/><SOAP-ENV:Body>< ns4:testResponse xmlns:ns2 = 'http://www.seconddecimal.com/ncsts/schemas/unrestricted/messages' xmlns:ns4 ='http://www.seconddecimal.com/ncsts/schemas/messages'><Document><testAmt >0</testAmt><testRate>0</testRate><test1Amt>0</test1Amt></Document></ns4:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Please refer the comments in the code and ask me for any details
Getting the below output and format is automatically updated by .NET which is undesirable
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
</s:Header>
<s:Body>
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><? xml version='1.0' encoding='utf-16'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'><SOAP-ENV:Header/><SOAP-ENV:Body>< ns4:testResponse xmlns:ns2 = 'http://www.seconddecimal.com/ncsts/schemas/unrestricted/messages' xmlns:ns4 ='http://www.seconddecimal.com/ncsts/schemas/messages'><Document><testAmt >0E-7</testAmt><testRate>0</testRate><test1Amt>0E-8</test1Amt></Document></ns4:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope></string>
</s:Body>
</s:Envelope>
See the attached code
/// <summary>
/// Allows adding in WS-Security header to incoming request
/// </summary>
public class TestMessageInspector : IClientMessageInspector
{
.......
public void AfterReceiveReply(ref Message reply, object correlationState)
{
// Here Need to replace or alter the reply Message (System.ServiceModel.Channels) content with other soap xml. Tried the below code and it does not alter the reply message content
var sb = new StringBuilder("<testAmt>88977</testAmt>");
using (var sw = XmlWriter.Create(new StringWriter(sb)))
{
reply.WriteMessage(sw);
sw.Flush();
} }
}
Sample Input:
<? xml version='1.0' encoding='utf-16'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'><SOAP-ENV:Header/><SOAP-ENV:Body>< ns4:testResponse xmlns:ns2 = 'http://www.seconddecimal.com/ncsts/schemas/unrestricted/messages' xmlns:ns4 ='http://www.seconddecimal.com/ncsts/schemas/messages'><Document><testAmt >0E-7</testAmt><testRate>0</testRate><test1Amt>0E-8</test1Amt></Document></ns4:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Sample Output:
<? xml version='1.0' encoding='utf-16'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'><SOAP-ENV:Header/><SOAP-ENV:Body>< ns4:testResponse xmlns:ns2 = 'http://www.seconddecimal.com/ncsts/schemas/unrestricted/messages' xmlns:ns4 ='http://www.seconddecimal.com/ncsts/schemas/messages'><Document><testAmt >0</testAmt><testRate>0</testRate><test1Amt>0</test1Amt></Document></ns4:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Please refer the comments in the code and ask me for any details
Getting the below output and format is automatically updated by .NET which is undesirable
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
</s:Header>
<s:Body>
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><? xml version='1.0' encoding='utf-16'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'><SOAP-ENV:Header/><SOAP-ENV:Body>< ns4:testResponse xmlns:ns2 = 'http://www.seconddecimal.com/ncsts/schemas/unrestricted/messages' xmlns:ns4 ='http://www.seconddecimal.com/ncsts/schemas/messages'><Document><testAmt >0E-7</testAmt><testRate>0</testRate><test1Amt>0E-8</test1Amt></Document></ns4:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope></string>
</s:Body>
</s:Envelope>