Hi.
We want to create a record of a custom entity in CRM from PHP. I've found multiple resources online that supposedly do the trick, and then I wrote a Create Request in C# to generate HTTP Request from SOAPLogger..
HTTP REQUEST
--------------------------------------------------
POST svenskinfra.xrm.sirocco.se/.../web
Content-Type: text/xml; charset=utf-8
SOAPAction: schemas.microsoft.com/.../Create
<s:Envelope xmlns:s="schemas.xmlsoap.org/.../envelope">
<s:Body>
<Create xmlns="schemas.microsoft.com/.../Services" xmlns:i="www.w3.org/.../XMLSchema-instance">
<entity xmlns:a="schemas.microsoft.com/.../Contracts">
<a:Attributes xmlns:b="schemas.datacontract.org/.../System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<b:key>custom_firstname</b:key>
<b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema">Firstname</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>custom_lastname</b:key>
<b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema">Lastname</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>custom_companyname</b:key>
<b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema">CompanyName</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>custom_telephone</b:key>
<b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema">0701122334</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>custom_email</b:key>
<b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema">test@test.com</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>custom_ipaddress</b:key>
<b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema">192.168.255.255</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>custom_message</b:key>
<b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema">This is a test message</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>custom_contacttype</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>881990000</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true" />
<a:FormattedValues xmlns:b="schemas.datacontract.org/.../System.Collections.Generic" />
<a:Id>00000000-0000-0000-0000-000000000000</a:Id>
<a:LogicalName>custom_contactrequest</a:LogicalName>
<a:RelatedEntities xmlns:b="schemas.datacontract.org/.../System.Collections.Generic" />
</entity>
</Create>
</s:Body>
</s:Envelope>
--------------------------------------------------
Now , I pasted everything, starting from the <s:Envelope> into a method in the PHP project I downloaded from GitHub. And I can successfully authenticate to CRM Server etc. but when it calls this method I get the following error from CRM trace:
Error in deserializing body of request message for operation 'Execute'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'Execute' and namespace 'schemas.microsoft.com/.../Services'. Found node type 'Element' with name 'Create' and namespace 'schemas.microsoft.com/.../Services'</Message>
This is what the method looks like:
function CreateContactRequest($authHeader, $url) {
try{
$xml = "<s:Body>";
$xml .= "<Create xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";
$xml .= "<entity xmlns:a=\"schemas.microsoft.com/.../Contracts\">";
$xml .= "<a:Attributes xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\">";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_firstname</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"www.w3.org/.../XMLSchema\">Förnamn</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_lastname</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"www.w3.org/.../XMLSchema\">Efternamn</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_companyname</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"www.w3.org/.../XMLSchema\">Företagsnamn</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_telephone</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"www.w3.org/.../XMLSchema\">0701122334</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_email</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"www.w3.org/.../XMLSchema\">test@test.com</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_ipaddress</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"www.w3.org/.../XMLSchema\">192.168.255.255</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_message</b:key>";
$xml .= "<b:value i:type=\"c:string\" xmlns:c=\"www.w3.org/.../XMLSchema\">Det här är ett testmeddelande. Detta meddelande kan vara max 2000 tecken.</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "<a:KeyValuePairOfstringanyType>";
$xml .= "<b:key>custom_contacttype</b:key>";
$xml .= "<b:value i:type=\"a:OptionSetValue\">";
$xml .= "<a:Value>881990000</a:Value>";
$xml .= "</b:value>";
$xml .= "</a:KeyValuePairOfstringanyType>";
$xml .= "</a:Attributes>";
$xml .= "<a:EntityState i:nil=\"true\" />";
$xml .= "<a:FormattedValues xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\" />";
$xml .= "<a:Id>00000000-0000-0000-0000-000000000000</a:Id>";
$xml .= "<a:LogicalName>custom_contactrequest</a:LogicalName>";
$xml .= "<a:RelatedEntities xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\" />";
$xml .= "</entity>";
$xml .= "</Create>";
$xml .= "</s:Body>";
$executeSoap = new CrmExecuteSoap ();
$response = $executeSoap->CreateSOAPRequest ( $authHeader, $xml, $url );
print_r($response);
} catch (SoapFault $exception) {
echo $exception->getMessage();
}
}
I basically need help how to specify the SoapAction as Create instead of Execute.. I don't know how to do it.
Thank you