I tried to do upload files from html page to self hosting WCF inside WPF application in local network.
Host like this:
Uri baseAddress = new Uri("http://localhost:8200/GettingStarted/");
ServiceHost selfHost = new ServiceHost(typeof(WCFUploader), baseAddress);
try
{
selfHost.AddServiceEndpoint(typeof(IWCFUploader), new WSHttpBinding(), "GettingStarted");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();}
But, when I try to access http://localhost:8200/GettingStarted/ by Javascript, I have an Access-Control-Allow-Origin 405 Http Error.
Anybody can help me?
Looks like a CORS (Cross-origin resource sharing) configuration issue.
Your JS is probably not hosted on localhost:8200
which requires you to add a specific HTTP header to allow for this XHR request.
This answer shall covert it all in details: https://stackoverflow.com/a/16039951/1503505
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.