c# - WCF Rest XML EndPoint.(HTTPPOST). Deserialise an external object -
i have service contract supposed accept widget input parameter. widget spec given me third party using contract. made appropriate data contracts , can use unit test (which using wcf service reference) serialize widget , http post.
it bare bones xml serialization embedded in body of httppost. not formed xml document. e.g.
stringwriter sw = new stringwriter(); xmltextwriter xtw = new xmltextwriter(sw); xtw.writestartelement("widget"); xtw.writeelementstring("datetime", widget.datetime); xtw.writestartelement("status"); foreach (myservref.status status in widget.status) { xtw.writestartelement("status"); xtw.writeelementstring("bay", status.bay.tostring()); xtw.writeelementstring("currentstate", status.currentstate.tostring()); xtw.writeelementstring("sector", status.sector.tostring()); xtw.writeelementstring("spaceid", status.spaceid.tostring()); xtw.writeelementstring("statusid", status.statusid.tostring()); xtw.writeelementstring("transitiondatetime", status.transitiondatetime); xtw.writeendelement(); } xtw.writeendelement(); xtw.writeelementstring("uniqueid", message.uniqueid.tostring()); xtw.writeendelement(); xtw.close(); string xml = sw.tostring();
when third party tries use contract there error 400. using formatted xml doc has namespace declarations in it. e.g.
<widget xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" uniqueid="8cf4df0f-e765-4afc-b6fa-cd90b07b67b2" datetime="2015-08-02t01:00:29.2213364z" xmlns="http://www.thesite.com/"> <status> <spaceid>00010003</spaceid> <statusid>1658038</statusid> </status> </widget>
the contract is:
[operationcontract]//don't decorate xml rest contracts use web.config response mycontract(widget widget);
the data contract is;
[datacontract(namespace = "")] public class widget { private string _uniqueidfield; private string _datetimefield; [datamember] public status[] status { get; set; } [datamember] public string uniqueid { { return _uniqueidfield; } set { _uniqueidfield = value; } } [datamember] public string datetime { { return _datetimefield; } set { _datetimefield = value; } } }
i have tried many options including alternate contract takes string parameter , used datacontractserializer deserialize widget.
essentially haven't clue how , floundering around looking correct way. appreciate can me solve this. thanks
if can make .net winform app , reference service work? if works should able wireshark requests see difference between winform app , third party's request.
Comments
Post a Comment