web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Can we Consume a HTTP based web service from a Web Resource in CRM Online?

(0) ShareShare
ReportReport
Posted on by 165

Hi Folks,

I have a HTTP based web service on client's network which works fine when I access it from a local HTML file with VPN being Connected but it throws an error (Access is denied) when accessed through a web resource of CRM. Service is CORS Enabled.

Can we access http based web service from CRM's web resource?

*This post is locked for comments

I have the same question (0)
  • sardar ahmed Profile Picture
    520 on at

    Hi Sahil,

    This seems to be a security issue of calling a service outside of the current domain. There are few solutions to this problem, 

    1. Using JSONP

    2.XDomainRequest. 

    Go through the below links to understand in detail.

    http://mscrmshop.blogspot.in/2012/07/crm2011-and-cross-domain-calls-part-1.html

    However, XDomainrequest is only compatible with IE.

    Regards

    Sardar Ahmed.

  • Verified answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi,

    Can you check if this service works from this site?

    http://www.test-cors.org

    If not then CORS is not enabled. If yes then you can compare the call from this site to yours and do this same way

    Also if CRM is https and service is http then it will not work

    Pawel

  • Sahil Profile Picture
    165 on at

    Hi sardar,

    I had already tried this blog earlier but was not able to achieve with my soap based service.

  • Sahil Profile Picture
    165 on at

    Hi Pawel,

    Just wanted to know one answer if you could help me with this error, why is chrome always showing this error even after enabling the CORS -

    Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404.

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi Sahil,

    But it's only Chrome or any browser? Are you sure the CORST is enlabled? Can you check the response in some Web Develoer tools (all browsers have them built-in, so you can check in Chrome) how the response looks like? It should have the header "Access-Control-Allow-Origin: *". If there is no such header, then CORS is not enabled. Check this, I had the same problem a couple of days ago and apparently the vendor who did web services I called enabled CORS only on one method and the rest were still not having this header.

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi Sahil,

    But it's only Chrome or any browser? Are you sure the CORS is enlabled? Can you check the response in some Web Develoer tools (all browsers have them built-in, so you can check in Chrome) how the response looks like? It should have the header "Access-Control-Allow-Origin: *". If there is no such header, then CORS is not enabled. Check this, I had the same problem a couple of days ago and apparently the vendor who did web services I called enabled CORS only on one method and the rest were still not having this header.

  • Sahil Profile Picture
    165 on at

    Hi Pawel,  

    Yes I have enabled CORS in web.config file of asmx service as shown below and please find below the error that I am receiving now:

    Web.Config file:

    <system.webServer>

       <validation validateIntegratedModeConfiguration="false" />

       <modules>

         <remove name="ScriptModule" />

         <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

       </modules>

       <handlers>

         <remove name="WebServiceHandlerFactory-Integrated" />

         <remove name="ScriptHandlerFactory" />

         <remove name="ScriptHandlerFactoryAppServices" />

         <remove name="ScriptResource" />

         <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

         <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

         <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

       </handlers>  

       <httpProtocol>

         <customHeaders>

           <add name="Access-Control-Allow-Origin" value="*" />

           <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />

           <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, Authorization" />

         </customHeaders>

       </httpProtocol>

     </system.webServer>

    Error:

    Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

    XMLHttpRequest cannot load localhost/SAP_SFDC_WebService.asmx. Response for preflight has invalid HTTP status code 405

  • tw0sh3ds Profile Picture
    5,600 on at

    Hi Sahil,

    I'm not an expert on web services, unfortunately :( And also last time I worked on asmx web services were zillions of years ago. I suggest you post your problem for example on stackoverflow as this is no longer CRM-specific thing, this is clearily the problem with web service and the way you call it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans