When the client is Silverlight or other technologies that do not support cross-origin by default, You need to manually enable cross-origin for WCF. The detailed method is as follows:
First, cross-origin files are required.
Clientaccesspolicy. xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <access-policy>
3 <cross-domain-access>
4 <policy>
5 <allow-from http-request-headers="*">
6 <domain uri="*"/>
7 </allow-from>
8 <grant-to>
9 <resource path="/" include-subpaths="true"/>
10 </grant-to>
11 </policy>
12 </cross-domain-access>
13 </access-policy>
Crossdomain. xml
1 <?xml version="1.0"?>
2 <cross-domain-policy>
3 <allow-access-from domain="*" />
4 </cross-domain-policy>
The preceding two cross-origin files must be stored in the root directory deployed on IIS.
The server config configuration is as follows:
1 <system.serviceModel>
2 <behaviors>
3 <serviceBehaviors>
4 <behavior name="LoggerBehavior">
5 <serviceDebug includeExceptionDetailInFaults="true" />
6 <serviceMetadata httpGetEnabled="true" />
7 </behavior>
8 </serviceBehaviors>
9 </behaviors>
10 <extensions>
11 </extensions>
12 <bindings>
13 <basicHttpBinding>
14 <binding name="UnSecureConversationBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1048576" maxBufferPoolSize="2097152" maxReceivedMessageSize="1048576" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
15 <readerQuotas maxDepth="32" maxStringContentLength="16777216" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
16 <security mode="None"></security>
17 </binding>
18 </basicHttpBinding>
19 </bindings>
20 <services>
21 <service behaviorConfiguration="LoggerBehavior" name="eTank.OIU.Service.OIUService" >
22 <endpoint binding="basicHttpBinding" bindingConfiguration="UnSecureConversationBinding" contract="eTank.OIU.Contract.IOIUUC" />
23 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
24 </service>
25 <service behaviorConfiguration="LoggerBehavior" name="eTank.OIU.Service.SMSConfigService" >
26 <endpoint binding="basicHttpBinding" bindingConfiguration="UnSecureConversationBinding" contract="eTank.OIU.Contract.ISMSConfigUC" />
27 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
28 </service>
29 </services>
30 </system.serviceModel>
Note the following When configuring the above servers:
1. <servicemetadata httpgetenabled = "true"/> in behavior is required;
2. Set the security level in binding to none, for example, <security mode = "NONE"> </Security>;
3. Add a metadata endpoint configuration for each service, for example, <endpoint address = "mex" binding = "mexhttpbinding" Contract = "imetadataexchange"/>;
After completing the preceding configuration, clients such as Silverlight can access the WCF Service across domains.