Click here to Skip to main content
15,877,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a console application that is sending an XML payload to a SOAP endpoint. I am getting error below when i try to submit the payload :

Log Written Date: 29/1/2020 1:23:59 PM

Error Line No : ine 101

Error Message: SoapException

Exception Type: System.Web.Services.Protocols.SoapException

Error Location : Exception Caught during processing: The element type "SSC" must be terminated by the matching end-tag "</SSC>".

This is despite that my XML is well-formed (at least in the code).
This is how im sending the payload :

transactions = GetContracts();
               StringBuilder sb = new StringBuilder();
               sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
               sb.Append("<Name>" + Helpers.parameters.sscUser + "</Name>");
               sb.Append("<BusinessUnit>" + Convert.ToString(Helpers.parameters.busUnit) + "</BusinessUnit>");
               sb.Append("<BudgetCode>" + Convert.ToString(Helpers.parameters.budgetCode) + "</BudgetCode>");

               foreach (Contracts contract in transactions) {

                   sb.Append("<EntryPeriod>" + contract.Period + "</EntryPeriod>");
                   sb.Append("<TransactionAmount>" + contract.Amount + "</TransactionAmount>");
                   sb.Append("<AnalysisCode1>" + contract.CompanyCode + "</AnalysisCode1>");



               var inputPayload = sb.ToString();
               if (authVoucher != null)
                   bool result = securityProvider.Validate(authVoucher);

                   if (result == true)

                     //some logic here

                       //execute routine and retrieve response to outresult
                           string outresult = componentExecutor.Execute(authVoucher, "", ComponentName, ComponentMethod, "", inputPayload);

                        catch (Exception ex)
                           string outresult = ex.Message.ToString();

What I have tried:

I have pasted a sample of my payload on a online XML validator and im getting error Root element is missing.
This seems an environment related issue and of all the solutions i searched i havent had any luck :

1. I have Verified that my .user file has no NULLS
2. I have Verified that my .csproj file is not empty
3. Searched for the line
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
in .csproj file but its not even there. I got a suggestion to comment out this file in some forum

3. navigated to C:\Users\<your user="">\Documents\Visual Studio <vs version="">\Backup Files\<your project=""> to check if there is both Recovered an Original files . What i get is two sets of both types of files
Original-May-18-2018-1209PM.<your project>.csproj
Recovered-May-18-2018-1209PM.<your project>.csproj
and as suggested i have renamed the Original set to <my_project>.csproj as suggested

I am stii getting the same XML validation error despite these changes.

What am i missing?
Updated 29-Jan-20 3:42am

You may try to remove the lines
(there are two of them) and see what happens, because there does not seem to be opening tags for these closing ones.
Share this answer
Maciej Los 29-Jan-20 9:48am    
phil.o 29-Jan-20 10:19am    
Thanks :)
Your XML is not well formatted.

You have twice added the row: sb.Append("</SunSystemsContext>");
The first one should be sb.Append("<SunSystemsContext>");

I would start by fixing that. It's possible this is causing the error.
Share this answer
CHill60 29-Jan-20 8:39am    
Overlap! And it does solve the problem by the way :-)
Maciej Los 29-Jan-20 9:48am    
sb.Append("<Name>" + Helpers.parameters.sscUser + "</Name>");
There is no starting tag for SunSystemsContextthat should be
sb.Append("<Name>" + Helpers.parameters.sscUser + "</Name>");
Share this answer
Tshumore 29-Jan-20 8:51am    
Typo, i have amended as necessary now im getting Exception Caught during processing: The entity name must immediately follow the '&' in the entity reference. on line
string outresult = componentExecutor.Execute(authVoucher, "", ComponentName, ComponentMethod, "", inputPayload);
CHill60 29-Jan-20 11:15am    
See @Richard-Deeming's comment in Solution 4 "(You'd better also hope that none of the values you're inserting ever contain characters which need to be encoded, otherwise you'll still end up with an invalid XML document.)"
Somewhere in your text you have an ampersand character and the parser starts looking for an entity following it … e.g. & l t ; indicates the < character and & amp ; indicates the &
Maciej Los 29-Jan-20 9:48am    
This is a good example of why you shouldn't use a StringBuilder to build an XML document. :)

(You'd better also hope that none of the values you're inserting ever contain characters which need to be encoded, otherwise you'll still end up with an invalid XML document.)

Using XLinq[^] would be so much easier:
XDocument document = new XDocument(
    new XDeclaration("1.0", "UTF-8", null),
    new XElement("SSC",
        new XElement("SunSystemsContext",
            new XElement("User",
                new XElement("Name", Helpers.parameters.sscUser)
            new XElement("BusinessUnit", Helpers.parameters.busUnit),
            new XElement("BudgetCode", Helpers.parameters.budgetCode)
        new XElement("Payload",
            transactions.Select(contract => new XElement("Ledger",
                new XElement("EntryPeriod", contract.Period),
                new XElement("TransactionAmount", contract.Amount),
                new XElement("AnalysisCode1", contract.CompanyCode)

string inputPayload = document.ToString();
Share this answer
Maciej Los 29-Jan-20 9:49am    
CHill60 29-Jan-20 11:18am    
I'd vote you up twice if I could - OP has just hit the "I have an ampersand in my text" problem that you more or less predicted
Maciej Los 29-Jan-20 13:57pm    
Me too ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900