<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="urn:microsoft-dynamics-schemas/error"> a:Microsoft.Dynamics.Nav.Service.WebServices.ServiceBrokerException</faultcode><faultstring xml:lang="en-AU">Parameter contactXML in method UpdateContacts in service ExampleService is null! </faultstring><detail><string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"> Parameter contactXML in method UpdateContacts in service ExampleService is null! </string></detail></s:Fault></s:Body></s:Envelope>
private ExampleService m_webservice = new ExampleService(); m_webservice.Credentials = new NetworkCredential("Username", "Password", "Domain"); List<contact> _list = new List<contact>(); var xDocument = XDocument.Parse(s_msgReceived.BodyAsString); var result = from e in xDocument.Descendants("bvc_User") // this is from the Service Broker message queue select e; foreach (var item in result) { contact _contact = new contact { no = "ContactNumber", name = item.Attribute("FirstName").Value, address = "Test 1", address2 = "Test 2" }; _list.Add(_contact); } contacts _contacts = new contacts(); _contacts.contact = (contact[])_list.ToArray(); var objectDocument = new XmlDocument(); using (XmlWriter writer = (objectDocument.CreateNavigator()).AppendChild()) { (new XmlSerializer(_contacts.GetType())).Serialize(writer, _contacts); writer.Close(); } XDocument xd = XDocument.Load(new XmlNodeReader(objectDocument)); m_webservice.UpdateContacts(_contacts); // this works fine but i can't ultimately do it this way due to the SQL Service Broker requirements // Build up the Soap web service envelope string requestString = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"; requestString += "<soap:Body>"; requestString += "<UpdateContacts xmlns=\"urn:microsoft-dynamics-schemas/codeunit/ExampleService\" >"; requestString += "<![CDATA["; requestString += xd; requestString += "]]>"; requestString += "</UpdateContacts>"; requestString += "</soap:Body>"; requestString += "</soap:Envelope>"; // Build up the HttpRequest that will hold our Soap message r = new httpRequestType(); r.url = m_webservice.Url; r.protocolVersion = "HTTP/1.1"; r.method = "POST"; r.headers = new headerType[2]; r.headers[0] = new headerType(); r.headers[0].name = "SOAPAction"; r.headers[0].value = "urn:microsoft-dynamics-schemas/codeunit/ExampleService:UpdateContacts"; r.headers[1] = new headerType(); r.headers[1].name = "Content-Type"; r.headers[1].value = "text/xml; charset=utf-8"; r.body = new ASCIIEncoding().GetBytes(requestString); ServiceRequest(r);
<contacts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <contact xmlns="urn:microsoft-dynamics-nav/xmlports/x50012"> <no>70191844</no> <name>Thomas</name> <address>Test 1</address> <address2>Test 2</address2> </contact> </contacts>
OBJECT Codeunit 50069 WebServiceExample { OBJECT-PROPERTIES { Date=09/05/11; Time=[ 5:17:34 PM]; Modified=Yes; } PROPERTIES { OnRun=BEGIN END; } CODE { PROCEDURE UpdateContacts@1101234001(ContactXML@1101234000 : XMLport 50012); BEGIN ContactXML.IMPORT; ContactXML.UpdateContacts(); END; PROCEDURE GetContact@1101240000(ContactNo@1101234002 : Code[20];VAR ContactXML@1101240000 : XMLport 50012) sReturn : Text[1024]; VAR contacts@1101234000 : Record 5050; BEGIN ContactXML.GetContacts(ContactNo); END; PROCEDURE GetALLContacts@1101234000(VAR ContactXML@1101234000 : XMLport 50012); BEGIN ContactXML.GetAllContacts; END; BEGIN END. } }
Comments
I experience this on 2009 Sp1. I'm trying to find out if this a bug in 2009 sp1 and if there is a hotfix for this. I will try with 2009 R2 and will let you know.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n