在开发环境下可以正常调用,但到发布后,为何不可以调用?
一、WCF的配置文件web.config,主要配置:behaviors、bindings、services
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true" />
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="65536000" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="NewBindingStationCnfg" maxReceivedMessageSize="655360000" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="NewBehavior" name="GlacierICR.SRV.BaseSearchSRV">
<host>
<baseAddresses>
<add baseAddress="http://localhost/GlacierICR.SRV/"/>
</baseAddresses>
</host>
<endpoint binding="wsHttpBinding" bindingConfiguration="NewBindingStationCnfg" contract="GlacierICR.ISRV.IBaseSearchSRV" />
</service>
</services>
</system.serviceModel>
二、WebClient的Web.Config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IBaseSearchSRV" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="655360000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/GlacierICR.SRV/BaseSearchSRV.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IBaseSearchSRV"
contract="BaseSearchRef.IBaseSearchSRV" name="WSHttpBinding_IBaseSearchSRV">
<identity>
<servicePrincipalName value="host/localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
如果只有上面两步,开发环境调试没问题,但发布后可能有问题,所以还要有第三步:
三、在WebClient下面要加两个文件
1. clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
2. crossdomain.xml
<?xml version="1.0" encoding="utf-8" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>