1

I have a request data which I am getting from some third party, which is in XML. I want to pass this data to C# from postman.

Request XML is as below :

<n0:MassMatchQCResponseMsg xmlns:prx="urn:sap.com:proxy:TST:/1SAI/TASF64A312341D275609721:740" xmlns:n0="http://example.com/compxref/abctype">
    <MassMatchDet>
        <InputProductNumber>456141</InputProductNumber>        
    </MassMatchDet>    
</n0:MassMatchQCResponseMsg>

Here, If I remove namespace alias n0 and post XML, its working fine with the following C# method.

[HttpPost]
public IActionResult Post([FromBody]MassMatchQCResponseMsg value)
{

}

but with n0, its showing status 500:Internal server error and fails. Can someone please tell me how to parse xml with namespace from Postman in C#.

Naresh Ravlani
  • 1,600
  • 13
  • 28
  • Not sure, but [might be this](https://stackoverflow.com/questions/3142403/c-handling-webclient-protocol-violation) – Crowcoder Dec 05 '18 at 12:07

1 Answers1

1

Sounds like you don't have your MassMatchQCResponseMsg configured with a Namespace.

[XmlRoot(Namespace="http://example.com/compxref/abctype")]
public class MassMatchQCResponseMsg{

    [XmlElement(Namespace="")]
    public MassMatchDet MassMatchDet {get;set;}
}

public class MassMatchDet
{
    public string InputProductNumber {get;set;}
}

Note the XmlRoot.Namespace and XmlElement.Namespace .

I test with the above code, it just works for me .

itminus
  • 23,772
  • 2
  • 53
  • 88