Search code examples
xmlsoapdynamics-crm

XML Prefix Attributes in SOAP Call CRM 2016


I am making a SOAP Call to CRM 2016 Organization via SOAPUI. Following is the working call:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <request i:type="a:CreateRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
    <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
      <a:KeyValuePairOfstringanyType>
        <b:key>Target</b:key>
        <b:value i:type="a:Entity">
          <a:Attributes>
            <a:KeyValuePairOfstringanyType>
              <b:key>subject</b:key>
              <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">SOAP UI Task</b:value>
            </a:KeyValuePairOfstringanyType>
            <a:KeyValuePairOfstringanyType>
              <b:key>description</b:key>
              <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">This is a test task created by SOAP UI.</b:value>
            </a:KeyValuePairOfstringanyType>
            <a:KeyValuePairOfstringanyType>
              <b:key>regardingobjectid</b:key>
              <b:value i:type="a:EntityReference">
                <a:Id>10A25151-5331-E711-80D0-000C2995F954</a:Id>
                <a:LogicalName>test_salesorder</a:LogicalName>
                <a:Name i:nil="true" />
              </b:value>
            </a:KeyValuePairOfstringanyType>
            <a:KeyValuePairOfstringanyType>
              <b:key>test_tasktype</b:key>
              <b:value i:type="a:OptionSetValue">
                <a:Value>970390000</a:Value>
              </b:value>
            </a:KeyValuePairOfstringanyType>
          </a:Attributes>
          <a:EntityState i:nil="true" />
          <a:FormattedValues />
          <a:Id>00000000-0000-0000-0000-000000000000</a:Id>
          <a:LogicalName>test_ordertask</a:LogicalName>
          <a:RelatedEntities />
        </b:value>
      </a:KeyValuePairOfstringanyType>
    </a:Parameters>
    <a:RequestId i:nil="true" />
    <a:RequestName>Create</a:RequestName>
  </request>
</Execute>

Changing

<a:EntityState i:nil="true" /> 
to 
<a:EntityState nil="true" />

is giving me a Formatter exception, I am not sure why making it in no namespace is giving exception? Is it mandatory to give prefix/namespace?

WSDL https://www.dropbox.com/s/1v7o7ol38jhd434/WSDL.txt?dl=0


Solution

  • In this case it is mandatory. Attributes, just like elements can have namespaces. And the default attribute that you have to set for a nillable element has a namespace, so it needs to be set. If not, this does not conform to the XML Schema Definition and will not validate.

    The nil attribute is defined in the XML Schema instance namespace, http://www.w3.org/2001/XMLSchema-instance (commonly associated with the prefix xsi), and applies only to XML instance documents, not XML Schema documents. A value of true for the xsi:nil attribute in an XML element explicitly specifies that the element has no content, whether child elements or body text.

    Original article