Silverlight 4 - 配置自托管 WCF 服务以使用 SSL
我有一个在同一服务器(自托管)上使用 WCF 服务的 Silverlight 4 应用程序。一切正常,但现在我想将我的 WCF 服务转换为使用 SSL。我正在使用 CustomBindings,但无法找到完成此操作的组合。我在客户端使用相对 URL,希望这不会造成问题。以下是我的 Web.config 文件的重要部分:
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<serviceTimeouts transactionTimeout="00:10:00"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="MyApp.Web.Services.ProjectService.customBinding0"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<services>
<service name="MyApp.Web.Services.ProjectService">
<endpoint address="" binding="customBinding" bindingConfiguration="MyApp.Web.Services.ProjectService.customBinding0"
contract="MyApp.Web.Services.ProjectService" />
</service>
我的 ClientConfig 如下所示:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_ProjectService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="../Services/ProjectService.svc" binding="customBinding"
bindingConfiguration="CustomBinding_ProjectService" contract="SearchProxy.ProjectService"
name="CustomBinding_ProjectService" />
</client>
</system.serviceModel>
</configuration>
我只是不明白绑定如何在服务器和客户端中工作。我希望有人能指出我正确的方向。
I have a Silverlight 4 application that uses WCF services on the same server (self-hosted). Everything works fine, but now I want to convert my WCF services to use SSL. I am using CustomBindings and can't quite find the combination to get this done. I am using relative URLs on the client side, and hope this is not causing a problem. Here are the important bits of my Web.config file:
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<serviceTimeouts transactionTimeout="00:10:00"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="MyApp.Web.Services.ProjectService.customBinding0"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<services>
<service name="MyApp.Web.Services.ProjectService">
<endpoint address="" binding="customBinding" bindingConfiguration="MyApp.Web.Services.ProjectService.customBinding0"
contract="MyApp.Web.Services.ProjectService" />
</service>
My ClientConfig looks like this:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_ProjectService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="../Services/ProjectService.svc" binding="customBinding"
bindingConfiguration="CustomBinding_ProjectService" contract="SearchProxy.ProjectService"
name="CustomBinding_ProjectService" />
</client>
</system.serviceModel>
</configuration>
I just don't understand how the bindings work in both the server and client. I'm hoping someone can point me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几点:
如果您想在本地主机上使用 SSL,则需要使用 IIS Express 7.5(如果您在服务器上进行开发,则需要使用完整的 IIS - 不太可能)。
您需要一个存储在 Web 应用程序根目录中的 clientaccesspolicy.xml 文件:
服务器端 Web.config 示例:
客户端示例:
IIS 7.5 将自动设置您的本地主机证书。
A few things:
If you want to use SSL on localhost you'll need to be using IIS Express 7.5 (or full IIS if you're on a server doing dev - unlikely).
You'll need a clientaccesspolicy.xml file stored in the root of the Web application:
Example server-side Web.config:
Example client-side:
IIS 7.5 will setup your localhost certificate automatically.
您可以更新客户项目上的服务参考吗?这应该使用正确的绑定更新 clientconfig 文件。我现在注意到的一件事是您正在使用;在客户端绑定和上关于服务。尝试更改客户端以使用以及。
此外,如果您的 SL 应用程序是从 HTTP:// 地址下载的,则对 HTTPS 中的服务的调用将被视为跨域调用,因此您还需要跨域策略文件。
Can you update the service reference on the client project? That should update the clientconfig file with the correct binding. One thing I am noticing right now is that you're using <httpTransport> on the client binding and <httpsTransport> on the service. Try changing the client to use <httpsTransport> as well.
Also, if your SL app is downloaded from an HTTP:// address, then a call to a service in HTTPS is considered to be a cross-domain call, so you'll need a cross-domain policy file as well.