Search code examples
c#phpsecuritydynamics-crm

Secure communication between PHP and C#


I am working on a PHP application that needs to integrate with Microsoft Dynamics CRM. I looked into ways of communicating directly between PHP and the MSCRM server, and ended up deciding to design it using C# bridge, i.e. the PHP app connects to a C# service, which interacts with MSCRM.

Now my issue is security, the communication between the C# service and the MSCRM server is secure, but between the PHP app and the C# service I'm a little bit confused about how to implement some sort of encryption.

Basically, I'm looking for recommendations, has anyone dealt with an issue like this before? What did you do? Is there a simple, secure way of doing this, or is it a complicated process?


Solution

  • You can get PHP to talk to CRM directly and securely. The extra bridge is just overhead that doesn't actually offer much benefit.

    Here's a blog post with a PHP helper class for CRM Online: http://www.hashtagcrm.com/?p=17

    Just start with that helper, and then extend it with any specific functionality you need. That helper even includes a sample function that shows how to add your own specific functionality:

      //Returns the Parent Account Name of the specified Contact
      public function sampleFunction($contactid){
    
        $getParentCustomer = '
                            <Retrieve xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                              <entityName>contact</entityName>
                              <id>'.$contactid.'</id>
                              <columnSet xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
                                <a:AllColumns>false</a:AllColumns>
                                <a:Columns xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                                  <b:string>parentcustomeridname</b:string>
                                </a:Columns>
                              </columnSet>
                            </Retrieve>';
    
        $getParentCustomerResult = $this->sendQuery($getParentCustomer, 'Retrieve');
    
        $responsedom = new DomDocument();
        $responsedom->loadXML($getParentCustomerResult);
        $KeyValuePairs = $responsedom->getElementsbyTagName("KeyValuePairOfstringanyType");
    
        foreach($KeyValuePairs as $results) {
          if ($results->childNodes->item(0)->nodeValue == "parentcustomeridname") {
            return $results->childNodes->item(1)->childNodes->item(0)->nodeValue;
          }
          else {
            return 'No Result';
          }
        }
      }
    

    Then in your main program, you would run something like this:

    require_once('dynamicsclient.php');
    $dynamicsClient = new dynamicsClient(0);
    
    //prints the Parent Account name of the specified Contact ID
    echo $dynamicsClient->sampleFunction("<CONTACTID>");