我有一个 Silverlight 应用程序,它有一些它使用的 WCF 服务。当我运行 silverlight 应用程序时,一切正常。其他人可以很好地使用它,但是,大多数用户都会出错。
“尝试向 URI 'xxxxx' 发出请求时出错。这可能是由于尝试以跨域方式访问服务而没有适当的跨域策略或不适合 SOAP 的策略服务。您可能需要联系服务所有者发布跨域策略文件,并确保它允许发送与 SOAP 相关的 HTTP 标头。此错误也可能是由于在 Web 服务代理中使用内部类型而没有使用 InternalsVisibleToAttribute 属性。有关更多详细信息,请参阅内部异常。
当这些用户访问我的 Silverlight 应用程序时,我启用了 WCF 跟踪并注意到一些错误:
1) 未找到配置评估上下文。2)内容类型application/soap+xml;charset=utf-8 被发送到需要 text/xml 的服务;字符集=utf-8
这是我的配置文件:
WCF 的服务器配置:
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="All"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows"/>
<identity impersonate="false"/>
<customErrors mode="Off" />
</system.web>
<appSettings>
</appSettings>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
这是我在 silverlight 中的客户端配置:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISLtoCRM" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
<binding name="BasicHttpBinding_ISLtoSQL" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://xxxx.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISLtoCRM" contract="SLCRMSrvc.ISLtoCRM"
name="BasicHttpBinding_ISLtoCRM" />
<endpoint address="http://yyyy.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISLtoSQL" contract="SLSQLSrvc.ISLtoSQL"
name="BasicHttpBinding_ISLtoSQL" />
</client>
</system.serviceModel>
</configuration>
WCF 服务托管在 Windows Server 2008 R2 上的 IIS 6.1 中。应用程序池设置为在特定用户下运行。托管管道模式是经典的,并且在 IIS 中的站点上启用了匿名身份验证。所有其他身份验证均被禁用。
有什么帮助解决这个问题吗?不知道为什么我自己和其他用户可以正常访问该应用程序,但大多数用户不能。是安全问题还是我创建 WCF 服务的方式有问题?
WCF 的更新服务器配置:
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="All"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
<authentication mode="Windows" />
</system.web>
<appSettings>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="CRMWCF.SLtoCRM" behaviorConfiguration="CRMBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="CRMWCF.ISLtoCRM" />
</service>
<service name="CRMWCF.SLtoSQL" behaviorConfiguration="CRMBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="CRMWCF.ISLtoSQL" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CRMBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Method" value="GET,PUT,POST,DELETE,OPTIONS"/>
<add name="Access-Control-Allow-Headers" value="Content-Type"/>
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>