Send SOAP WebService Request (Content-Type and Xml Prefix questions)
sorry for the questions, but since i haven't found any serious AL forum yet and i'm struggeling converting C/SIDE to AL... This time it's about a SOAP WebService call from AL to AL, and i have two issues:
How to set the content type to "text/xml; charset=utf-8"? I tried content.GetHeaders and Add, but than i do have multiple content types. Without, i do receive a unsupported media error.
Content.GetHeaders(Headers);
Content.WriteFrom(CreateMySoapWebServiceXml);
RequestMessage.SetRequestUri('http://febee32f3cb2:7047/NAV/WS/CRONUS%20AG/Codeunit/MyPublishedWebService');
RequestMessage.Method('POST');
RequestMessage.Content(Content);
RequestMessage.GetHeaders(Headers);
Headers.Add('SOAPAction',GetSoapServiceName + ':' + GetSoapMethodName);
if Client.Send(RequestMessage,ResponseMessage) then begin
// ....
end;
The second question is about the prefixes "soap" for XML. In .NET i the CreateElement had an overload for CreateElement(Prefix,LocalName,NamespaceUri). The XmlElement.Create does only have LocalName and NamespaceUri as parameters.
Thanks in advance!
Hello Skordas,
Regarding Headers - I believe you can resolve the first issue by first calling Remove on the RequestMessage headers to remove the default Content-Type header value, and then call Add to replace it with yours.
I am not sure about your second issue.
hi, thank you vytjak. It worked 👍
Only prefix for Xml CreateElement missing. Current workaround is to write the xml in a text variable :(
Could you try el := CreateElement(LocalName, NamespaceUri) el.Add(XmlAttribute.CreateNamespaceDeclaration(NamespacePrefix, NamespaceUri))
I would add the namespace declaration at the top of the document and then use only CreateElement(LocalName, NamespaceUri) in all the places I want an element in that namespace.
hi atoader, thank you very much. I would have never used the XmlAttribute to do this, but it seems to work.
Document := XmlDocument.Create;
RootNode := XmlElement.Create('envelope','http://test').AsXmlNode;
RootNode.AsXmlElement.Add(XmlAttribute.CreateNamespaceDeclaration('prefix','http://test'));
Document.Add(RootNode);
ChildNode := XmlElement.Create('child','http://test').AsXmlNode;
RootNode.AsXmlElement.Add(ChildNode);
Result:
<prefix:envelope xmlns:prefix="http://test"> <prefix:child /> </prefix:envelope>
I am running into same issue as your question. What is the syntax for removing the headers on request message?
i get the error attached.
This is what i have
Content.GetHeaders(Headers);
Content.WriteFrom(XMLRequestString);
RequestMessage.SetRequestUri('http://testurl.com/service/service1.asmx');
RequestMessage.Method('POST');
RequestMessage.Content(Content);
Headers.Remove('Content-Type');
RequestMessage.GetHeaders(Headers);
Headers.Add('Content-Type','text/xml');
Headers.Add('SOAPAction','http://tempuri.org/InsertProduct');
Client.Send(RequestMessage, ResponseMessage);
//temp
Hello naveenpinnama I have had the same error message and found that I had to define 2 seperate HttpHeaders variables, as some Header values are Content Headers and some are Request Message Headers, then the Remove and Add methods worked. See example below...
HttpWebRequest.SetRequestUri(ServiceUrl);
HttpWebRequest.Method := 'POST';
HttpWebRequest.Content(HttpReqContent);
HttpWebRequest.GetHeaders(ReqHeaders);
HttpReqContent.GetHeaders(ContentHeaders);
ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type',ContentTypeTxt);
ReqHeaders.Remove('Accept-Encoding');
ReqHeaders.Add('Accept-Encoding','gzip');
Hope that helps!
Thanks Jennis.
On Tue, Jan 9, 2018 at 11:34 PM, jennisoliman [email protected] wrote:
Hello naveenpinnama I have had the same error message and found that I had to define 2 seperate HttpHeaders variables, as some Header values are Content Headers and some are Request Message Headers, then the Remove and Add methods worked. See example below...
HttpWebRequest.SetRequestUri(ServiceUrl); HttpWebRequest.Method := 'POST'; HttpWebRequest.Content(HttpReqContent); HttpWebRequest.GetHeaders(ReqHeaders); HttpReqContent.GetHeaders(ContentHeaders); ContentHeaders.Remove('Content-Type'); ContentHeaders.Add('Content-Type',ContentTypeTxt); ReqHeaders.Remove('Accept-Encoding'); ReqHeaders.Add('Accept-Encoding','gzip');Hope that helps!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/AL/issues/897#issuecomment-356522784, or mute the thread https://github.com/notifications/unsubscribe-auth/AgvGTPTJhevBGv6pipn1TRkbp_DZ4nsmks5tJGgFgaJpZM4QVEBi .