Home > database >  An error occurred while trying to make a request to URI http://localhost:XXXXX/XXXX
An error occurred while trying to make a request to URI http://localhost:XXXXX/XXXX

Time:12-25

I am using a SharePoint Login page which contains the button of a SilverLight application, the login page will be loaded at the client side and by pressing the button the SilverLight application must open the local WCF service which is installed on the client machine and it must generate a OTP, but in my case this is not happening.

The WCF Uri that, I am using is like this http://localhost:12345/service and when I press the button on the login page and I have noticed in fiddler that the call goes as http://localhost:12345/clientaccesspolicy.xml.

I have placed the ClientAccessPolicy.xml and CrossDomain.xml in the root folder of the system and the project folder also.

I have also tried to give the ClientAccessPolicy.xml through the WCF service but that was not working

Here is the complete Stack Trace of the error.

{System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'http://localhost:XXXXX/XXXXX'.
 This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place,
 or a policy that is unsuitable for SOAP services. 
 You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent.
 This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. 
 Please see the inner exception for more details. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.
   at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
   --- End of inner exception stack trace ---
   at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
   at SLLogin.iCubeWCFsvc.Service1Client.Service1ClientChannel.EndGenKey(IAsyncResult result)
   at SLLogin.iCubeWCFsvc.Service1Client.SLLogin.iCubeWCFsvc.IService1.EndGenKey(IAsyncResult result)
   at SLLogin.iCubeWCFsvc.Service1Client.OnEndGenKey(IAsyncResult result)
   at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}

CodePudding user response:

I resolved my issue this way. If you are using the service through IIS express locally with visual studio make sure to include ClientAccessPolicy.xml and CrossDomainPolicy.xml files in the web service project's root folder.

clientaccesspolicy.xml

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="SOAPAction">
        <domain uri="*" />
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true" />
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

CrossDomain.xml

<?xml version="1.0" encoding="utf-8" ?>
<cross-domain-policy>
  <allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type" secure="true" />
</cross-domain-policy>

refer: http://www.allenconway.net/2010/07/fixing-attempting-to-access-service-in.html

CodePudding user response:

Finally, I have found out a solution for my problem. I got this error when i was trying to access the silverlight button from page on a client system. This is caused because the localhost is not able get the ClientAccessPolicy.xml and CrossDomainPolicy.xml in the client machine.

The solution for this problem is to copy the ClientAccessPolicy.xml and CrossDomainPolicy.xml in the root folder of the client machine and at the same time the best way is to send the policy files across the WCF or WPF service to the localhost URL used as a service reference.

For reference on how to send ClientAccessPolicy.xml and CrossDomainPolicy.xml refer these links.

https://blogs.msdn.microsoft.com/carlosfigueira/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services/

https://code.msdn.microsoft.com/Accessing-self-hosted-WCF-7872c931

Thanks & Regards

Harsha

  • Related