维护一个老程序,在用户增加ISA作为局域网与互联网之间的防火墙之后,在互联网上的用户就无法让页面中的silverlight访问WCF服务了,但在与服务器在同一个局域网中的用户使用照常。
使用ISA使得互联网的用户必须通过HTTPS协议访问防火墙后的WEB服务器,WCF服务host在其中,而ISA里面局域网中的用户直接使用HTTP协议来访问这个服务,ISA对HTTPS的转换是透明的。
最后的解决方案是服务端的配置不变,在silverlight的ServiceReferences.ClientConfig添加一个binding和endpoint,endpoint的address等与原有的endpoint相同,只是使用心得binding,而新的binding与原有的binding只是在security改为Transport——与HTTPS都应,在互联网用HTTPS访问服务时用新的endpoint就可以了。修改后并不是很难理解,但客户端与服务端配置不配对让人有些奇怪。
例子如下:
Web.conf中的相关配置
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<serviceBehaviors>
<behavior name="FPServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" maxConcurrentInstances="1000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_Service" openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" closeTimeout="01:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="FPServiceBehavior" name="WcfPlanningLibrary.PlanLine">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_FPService" contract="WcfPlanningLibrary.IPlanLine">
</endpoint>
</service>
<service behaviorConfiguration="ServiceBehavior" name="FPMVService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_FPService" contract="FPMVService">
</endpoint>
</service>
</services>
</system.serviceModel>
ServiceReferences.ClientConfig的相关配置
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Service" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00" closeTimeout="00:10:00" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly" />
</binding>
<binding name="BasicHttpBinding_Service1" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00" closeTimeout="00:10:00" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://XXX/WCFWeb/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service"
contract="Service.Service" name="BasicHttpBinding_Service" />
<endpoint address="https://XXX/WCFWeb/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service1"
contract="Service.Service" name="BasicHttpBinding_Service1" />
</client>
</system.serviceModel>
其中BasicHttpBinding_Service1是新的binding和新的endpoint的名字。