Angular CLI: 6.1.5
Node: 8.11.4
OS: win32 x64
I'm struggling to understand this error. I under stand it has to do with CORS, but I can't seem to get around it and it's localhost, connecting to localhost. Angular is running on port 4200, and my service is running on port 80 via WCF from a Windows Service. Both are on localhost, so I'm not sure why I'm getting the error.. Even if I guess this working, I would need to understand the error when I'm rolling into upper environments. I tried http.cors.enabled: false without success. I'm not sure I understand this purpose.
import { Response } from '@angular/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
export enum POST_TYPE {
POST = 1,
GET = 2
};
export class RestService {
private headers: HttpHeaders;
constructor(private http: HttpClient) {};
public getResponse = function(postType: POST_TYPE, restURL: string, postData: string) {
this.headers = new HttpHeaders({
'Content-Type': 'text/xml;charset=UTF-8',
'http.cors.enabled': 'true',
'http.cors.allow-origin': '*',
'http.cors.allow-methods': 'OPTIONS, HEAD, GET, POST, PUT, DELETE',
});
if ( postType === POST_TYPE.POST && postData != null) {
return this.http.post(restURL, postData, {headers: this.headers})
.map((res: Response) => res.json());
} else {
return this.http.get(restURL)
.map((res: Response) => res.json());
}
};
}
EDIT (ADD, app.config used by WCF Library, not on IIS, within a Windows Service):
<system.serviceModel>
<services>
<service name="WCFListener.ABCMonitor" behaviorConfiguration="Throttled">
<endpoint address="" binding="webHttpBinding" contract="WCFListener.IABCMonitor" behaviorConfiguration="web">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/ABC/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Throttled">
<serviceTimeouts transactionTimeout="00:01:00"/>
<!--
https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/servicethrottling
maxConcurrentCalls:
A positive integer that limits the number of messages that currently process across a ServiceHost.
Calls in excess of the limit are queued. Setting this value to 0 is equivalent to setting it to Int32.MaxValue.
The default is 16 * processor count.
maxConcurrentSessions:
A positive integer that limits the number of InstanceContext objects that execute at one time across a ServiceHost.
Requests to create additional instances are queued and complete when a slot below the limit becomes available.
The default is the sum of maxConcurrentSessions and MaxConcurrentCalls
maxConcurrentInstances:
A positive integer that limits the number of sessions a ServiceHost object can accept.
The service will accept connections in excess of the limit, but only the channels below the limit are active
(messages are read from the channel).
Setting this value to 0 is equivalent to setting it to Int32.MaxValue.
The default is 100 * processor count.
-->
<serviceThrottling maxConcurrentCalls="5" maxConcurrentSessions="5" maxConcurrentInstances="5"/>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="False" httpsGetEnabled="False"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true.
Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>