azure-sdk-for-php
azure-sdk-for-php copied to clipboard
Can't receive messages from the Service Bus that originated from Dynamics CRM
I guess this is the same issue as https://github.com/Azure/azure-sdk-for-python/issues/493, and that there is an issue on the Server side of the Service Bus.
I have the following message in my queue. The Service Bus Explorer reads it fine, but the PHP SDK gives the following error:
<Error><Code>500</Code><Detail>The server was unable to process the request; please retry the operation. If the problem persists, please contact your Service Bus administrator and provide the tracking id. TrackingId:31745779-0970-4a91-a23e-22c02718afb3_G38,TimeStamp:4/26/2016 12:03:02 PM</Detail></Error>.
The messages is pushed on the Service Bus by Microsoft Dynamics CRM Online.
Okay, it seems to be related to the Message Properties. As soon as there is a property with a key that contains a : or a / (quite crucial for urls), the 500 internal server error is thrown. This is probably due to the fact that the messages are converted to key: value pairs, and the colon and slash aren't properly escaped in the Service Bus code.
I've raised the question on the Service Bus forums in the hope a Microsoft dev sees it: https://social.msdn.microsoft.com/Forums/azure/en-US/7f789dc5-1172-4432-9629-20220f434746/bug-rest-api-throws-500-internal-server-error-when-a-message-contains-a-message-property-with-a?forum=servbus
@michaelarnauts, are you using property names with ":" or "/"? Property values support ":" or "/", but names don't.
Yaqi
@yaqiyang that's what I expected, but Dynamics CRM uses URL's as key's. This is working fine with the C# api, but not with the REST API, since they map the properties to HTTP headers in a key: value type without encoding the key somehow. If : and / are not allowed, the Service Bus should not allow the message.
{
"body": "40 16 52 65 6D 6F 74 65 45 78 65 63 75 74 69 6F 6E 43 6F 6E 74 ",
"contentType": null,
"correlationId": "{b5dc687e-023b-4d51-806f-bf03a741151d}",
"deliveryCount": 1,
"enqueuedSequenceNumber": 0,
"enqueuedTimeUtc": "2016-04-22T13:26:29.4103252Z",
"expiresAtUtc": "9999-12-31T23:59:59.9999999",
"forcePersistence": false,
"isBodyConsumed": false,
"label": null,
"lockedUntilUtc": null,
"lockToken": null,
"messageId": "f2dd02f478b54a8190ab902c5b8bcadf",
"partitionKey": "420",
"properties": {
"http://schemas.microsoft.com/xrm/2011/Claims/Organization": "testxxx.crm4.dynamics.com",
"http://schemas.microsoft.com/xrm/2011/Claims/User": null,
"http://schemas.microsoft.com/xrm/2011/Claims/InitiatingUser": null,
"http://schemas.microsoft.com/xrm/2011/Claims/EntityLogicalName": "contact",
"http://schemas.microsoft.com/xrm/2011/Claims/RequestName": "Create",
"singularityheader": "appId=119*ctrlguid=1452407010*acctguid=c0b62453-c4d6-42d2-82a1-a9e7ccf63450*btid=10069*guid=3cdcb61f-f3ce-4f3f-922e-90bca6ed54b7*exitguid=8*unresolvedexitid=25381*cidfrom=385*etypeorder=DOTNETMessaging*esubtype=DOTNETMessaging*cidto={[UNRESOLVED][25381]}"
},
"replyTo": null,
"replyToSessionId": null,
"scheduledEnqueueTimeUtc": "0001-01-01T00:00:00",
"sequenceNumber": 50384020831207427,
"sessionId": null,
"size": 19642,
"state": 0,
"timeToLive": "10675199.02:48:05.4775807",
"to": null,
"viaPartitionKey": null
}
In that case, it should work if you call urlencode() on the property name before passing it to the API calls.
Shouldn't the Service Bus Web API do that before putting the properties in a HTTP header?
You can try the Pull Request I created (https://github.com/Azure/azure-sdk-for-php/pull/824) and see if it fixes your issue.
Yaqi
@yaqiyang this won't fix my problem (but it could fix someone elses problem if he tries to send those messages to the Service Bus).
Dynamics CRM (what uses the C# api) is putting the messages in the service bus, not this SDK. The message is already un-urlencoded there. The Web API should urlencode it before sending it to me.
Where does the error occur in PHP? Can you give me a call stack?
I did more research on this issue. It seems the PHP SDK does not support sb:// endpoints for service bus which is the way to send/receive custom properties embedded with special characters. So there is no easy solution at this time.
We made a workaround by creating a C# middleware that reads out the service bus and sends it encoded in a json to a callback url that we handle with PHP.