web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Building xml by code

(5) ShareShare
ReportReport
Posted on by 478
Hi,

I want to prepare this xml by gathering data from tables, then make an http request to send it

is the correct way to build every single node with x++ code like this?
 XMLDocument xmlDocument = XMLDocument::newBlank();

 XMLElement elementEnv;

 elementEnv = xmlDocument.createElement3('S', 'Envelope', 'http://schemas.xmlsoap.org/soap/envelope/');
 xmlDocument.appendChild(elementEnv);

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Header xmlns:vwsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <To xmlns="http://www.w3.org/2005/08/addressing">ws://dummy.endpoint.com/QQ</To>
    <ReTo xmlns="http://www.w3.org/2005/08/addressing">
      <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
    </ReTo>
    <MessageID xmlns="http://www.w3.org/2005/08/addressing">PlaceholderMessageID</MessageID>
    <Field1 xmlns="http://dummy.domain.com/ns-auth">PlaceholderUser</Field1>
    <Field2 xmlns="http://dummy.domain.com/ns-addr"/>
    <Field3 xmlns="http://dummy.domain.com/ns-addr"/>
    <Field4 xmlns="http://dummy.domain.com/ns-addr"/>
    <Field5 xmlns="http://dummy.domain.com/ns-addr">PlaceholderSystem</Field5>
    <wsse:Security>
      <wsse:UsernameToken>
        <wsse:Username vwsu:Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
                       vwsu:NameQualifier="http://dummy.domain.com/ns-qualifier#Dummy">
          PlaceholderUser
        </wsse:Username>
      </wsse:UsernameToken>
    </wsse:Security>
  </S:Header>
  <S:Body>
    <n1:RootElement xmlns:n1="http://dummy.domain.com/n1"
                    xmlns="http://dummy.domain.com/ns-default"
                    xmlns:p1="http://dummy.domain.com/ns1"
                    xmlns:p2="http://dummy.domain.com/ns2"
                    xmlns:p3="http://dummy.domain.com/ns3"
                    xmlns:p4="http://dummy.domain.com/ns4"
                    xmlns:p5="http://dummy.domain.com/ns5"
                    xmlns:p6="http://dummy.domain.com/ns6"
                    xmlns:p7="http://dummy.domain.com/ns7"
                    xmlns:p8="http://dummy.domain.com/ns8">
      <Element1>
        <Element2>
          <Element3>
            <FieldA>Value1</FieldA>
            <FieldB>Value2</FieldB>
            <FieldC>Value3</FieldC>
          </Element3>
        </Element2>
      </Element1>
      <n1:Element4>
        <n1:FieldD>true</n1:FieldD>
        <n1:FieldE>true</n1:FieldE>
        <n1:FieldF>true</n1:FieldF>
        <n1:FieldG>Value4</n1:FieldG>
        <n1:FieldH>Value5</n1:FieldH>
        <n1:FieldI/>
      </n1:Element4>
      <p7:Element5>
        <p7:Element6>
          <p7:Element7>
            <Element2>
              <Element3>
                <FieldA>Value6</FieldA>
                <FieldB>Value7</FieldB>
                <FieldC>Value8</FieldC>
              </Element3>
            </Element2>
            <p7:Element8>
              <Element9>
                <Element10>
                  <FieldD/>
                </Element10>
              </Element9>
            </p7:Element8>
          </p7:Element7>
        </p7:Element6>
        <p8:Element11>
          <p8:FieldI>-1</p8:FieldI>
        </p8:Element11>
        <p7:Element12>
          <p7:FieldJ languageID="en" listID="List01" listVersionID="1" name="Name1">Value9</p7:FieldJ>
          <p7:FieldK languageID="en" listID="List02" listVersionID="1" name="Name2">Value10</p7:FieldK>
        </p7:Element12>
        <p7:Element13>
          <p7:FieldL>
            <p7:FieldM languageID="en" listID="List03" listVersionID="1" name="Exact Day">Day</p7:FieldM>
            <p7:FieldN>2099-01-01</p7:FieldN>
          </p7:FieldL>
        </p7:Element13>
        <p7:FieldO>PlaceholderCategory</p7:FieldO>
        <p7:Tags>
          <p7:Tag>
            <p7:FieldP>INTERFACE</p7:FieldP>
            <p7:FieldQ>ORIGIN</p7:FieldQ>
            <p7:FieldR>TAG123</p7:FieldR>
          </p7:Tag>
        </p7:Tags>
        <p7:Element14>
          <p7:Element15>
            <p7:FieldA languageID="en" listID="ISO999" listVersionID="1" name="DummyCountry">XXX</p7:FieldA>
            <p7:FieldB>YYY</p7:FieldB>
            <p7:FieldC>Z</p7:FieldC>
          </p7:Element15>
        </p7:Element14>
      </p7:Element5>
      <p3:Element16>
        <p3:FieldS>
          <p3:FieldT>-1</p3:FieldT>
        </p3:FieldS>
        <p3:FieldU>ABC123</p3:FieldU>
        <p3:FieldV>XYZ</p3:FieldV>
        <p3:FieldW>2099</p3:FieldW>
        <p3:FieldX>PROG</p3:FieldX>
        <p3:FieldY>
          <p3:Sub1>
            <p3:Sub2>
              <p3:FieldZ>
                <p3:Code1>A1</p3:Code1>
              </p3:FieldZ>
              <p3:FieldAA>
                <p3:Code2>A1</p3:Code2>
              </p3:FieldAA>
            </p3:Sub2>
          </p3:Sub1>
          <p3:Sub3>
            <p3:Sub4>
              <p3:FieldAB>
                <p3:Code3>INT123</p3:Code3>
              </p3:FieldAB>
            </p3:Sub4>
          </p3:Sub3>
        </p3:FieldY>
        <p3:TechData>
          <p3:AttributesList>
            <p3:Attributes>
              <p3:Source>PLACEHOLDER</p3:Source>
              <p3:AttrGroup>
                <p3:Code>CODEX</p3:Code>
              </p3:AttrGroup>
              <p3:Attr>
                <p3:Code>CODEY</p3:Code>
              </p3:Attr>
              <p3:ScaleUnit/>
              <p3:Value>999</p3:Value>
            </p3:Attributes>
          </p3:AttributesList>
        </p3:TechData>
      </p3:Element16>
    </n1:RootElement>
  </S:Body>
</S:Envelope>
 
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    This a SOAP message. Why exactly do you want compose it by yourself rather then simply use existing SOAP tools? For example, Visual Studio can generate code for calling the web service, including contract objects. You'll just populate the objects; all the details such as the serialization to XML will be dealt with for you. Your current attempts means a lot of work (you even don't know how to do it) just to get a worse solution than what's already available. Doing so doesn't sound wise to me.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
  • DELDYN Profile Picture
    478 on at
    Hi @Martin Dráb,

    What tool are you referring to?
    can you please guide me? what to do exactly?
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    Don't follow the suggested answer. It tells you something about you wanted, but it ignores the fact that you shouldn't be doing it at all. You won't be dealing with the problem at all when use the correct desing. You'll have less code to write, test and maintain and you'll get a more flexible solution.
     
  • DELDYN Profile Picture
    478 on at
    Hi @Martin Dráb


    in the article u sent me, which url shall i put here? 
    and what type of C# project shall i create? 
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    Please start by telling us more about your scenario. Then let's design a solution only then start implementing it and talking about details.

    What information do you have about the web service you want to call? What will you do with it in F&O?
    Are you sure that you want to call it directly? Maybe you want to be able to send messages even if the service is down (for maintenance, because of a network issue or so), you want to use some transformations, caching or so.
     
    Anyway, if calling the web service directly is the right design (which we don't know yet) and you want to utilize the code generator it in Visual Studio (which I recommend), you should create a class library project. You aren't creating a separate application; you'll just add an extra library to F&O. Which URL you should use depends on what web service you want to call.
  • DELDYN Profile Picture
    478 on at
    Hi Martin,

    There is a button i created in FO, when clicked, i need to gather the information from some of the tables, prepare this xml and send it to an external API

    when i do it with postman:

    I call authentication api to get a bearer token
    then i call the actual api, where i put the token and put in the body the xml/soap
    then i send it and i get a response back

    now i want to do the same thing i do with postman but in x++

    when i clicked add service reference (following the article) and put the same api url, it didn't work, i got the error below. I also tried add  ?wsdl at the end of the url but also it didn't work
    There was an error downloading 'https://xx/xx/xx/$metadata'.
    The request failed with HTTP status 404: Resource Not Found.
    Metadata contains a reference that cannot be resolved: 'https://xx/xx/xx'.
    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.
    The remote server returned an error: (401) Unauthorized.
    If the service is defined in the current solution, try building the solution and adding the service reference again.
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    Please give us some basic information about the web service and tell us what exactly you did in Visual Studio. The error message suggests that you're trying to handle it as an OData service, but the XML is SOAP message, not an OData request. But maybe the error is misleading and you're simply using a wrong URL or the problem is caused by authorization. Does the URL point to WSDL, or what kind of URL is it? What do you get when you open it in a browser.
     
    We really need more information from you., otherwise we can't help you.
  • DELDYN Profile Picture
    478 on at
    Hi @Martin Dráb,

    what basic information you need to know about the api?

    I mentioned that it requires authentication first to call the api through postman
    https://login.microsoftonline.com/tenantId/oauth2/V2.0/token
    then i call the original api with the token
    https://api.f.w/x-proxy/y 

    the body of the api is xml and the response is xml



    if i call the url through browser, it returns this
    i tried
    https://api.f.w/x-proxy/y
    and
    https://api.f.w/x-proxy/y?wsdl




    And what i did in visual studio is like the first step in the article, that i created a c# library
    i tried this
    https://api.f.w/x-proxy/y 
    and 
    https://api.f.w/x-proxy/y?wsdl
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    You need to realize that there are different types of web services (consumed in different ways), therefore saying just that you send something through HTTP isn't sufficient. You should have started with something like "I'm calling a SOAP web service with OAuth2" and told us what instructions you got from the owner of the web service. They could have developed anything; we can't just guess what they did and how it could be used. There are standard like SOAP, of course, but they may be used in different ways and implementers could even deviate from the standard.
     
    Ask the owner of the web service about the WSDL endpoint. https://api.f.w/x-proxy/y?wsdl apparently doesn't work, as you tested in the browser, so you can't expect Visual Studio to generate anything based on this missing information.
     
    By the way, your screenshot shows that the service call doesn't work even when called from Postman, because you're getting an internal server error. Shouldn't you address that too before continuing?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans