Using URL redirect instead of input param for WCF

2019-09-19 02:09发布

问题:

While investigating the Organization.svc in Dynamics CRM, I found that it is using URL redirect for changing the Organizations. That means for each Organization it simulate URL to access Organization.svc.

There is just one SVC file but multiple URLs to access it e.g. Organization Org1 will have URL http://CRMserver_name/Org1/XRMServices/2011/Organization.svc and Org2 will have http://CRMserver_name/Org2/XRMServices/2011/Organization.svc

I was wondering if there is any benefits for doing this as compare to passing input param to SVC. Please share your thoughts on the pros and cons for these two things.

回答1:

I learned something new today. Pardon me if you know this already.

There are two different things –

  1. URL routing - http://msdn.microsoft.com/en-us/library/ee358760.aspx
  2. URL rewrite - http://msdn.microsoft.com/en-us/library/ms972974.aspx

URL routing is ultimate thing. It is totally virtual and no need to register routes in IIS. So now I know why Dynamics CRM is using it. Using routing client doesn’t need to specify Organization name for each method call of WCF service. While creating client object, URL itself gives that info. Client only needs to do this once and all methods are now aware of Organization name for particular WCF call.

This example can help get you started with URL routing for WCF - http://msdn.microsoft.com/en-us/library/ee662952.aspx

Hope this helps someone! -Nilesh



回答2:

My guess would be cleaner URLs and also it follows a sort of conventions for Dynamics CRM. As far as I can tell, URLs have always been in the format http://CRMserver_name/OrgName/...