gpt4 book ai didi

Silverlight 4 - 配置自承载 WCF 服务以使用 SSL

转载 作者:太空宇宙 更新时间:2023-11-03 13:29:30 25 4
gpt4 key购买 nike

我有一个 Silverlight 4 应用程序,它在同一台服务器(自托管)上使用 WCF 服务。一切正常,但现在我想将我的 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>

我只是不明白绑定(bind)在服务器和客户端中是如何工作的。我希望有人能给我指出正确的方向。

最佳答案

一些事情:

如果您想在本地主机上使用 SSL,则需要使用 IIS Express 7.5(如果您在服务器上进行开发,则需要使用完整的 IIS——不太可能)。

您需要一个存储在 Web 应用程序根目录中的 clientaccesspolicy.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers= "SOAPAction">
<domain uri="https://*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

服务器端 Web.config 示例:

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SecureBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>

<behaviors>
<serviceBehaviors>
<behavior name="SomeBehavior" >
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="https" port="443" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>

<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="SomeService.svc" service="MySilverlight.Web.SomeService"/>
</serviceActivations>
</serviceHostingEnvironment>

<services>
<service name="MySilverlight.Web.SomeService"
behaviorConfiguration="SomeBehavior">

<endpoint address="SomeService"
binding="basicHttpBinding"
bindingConfiguration="SecureBasicHttpBinding"
bindingNamespace="https://MySilverlight.Web.SomeService"
contract="MySilverlight.Web.ISomeService">
</endpoint>

<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>

客户端示例:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISomeService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/SomeService.svc/SomeService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISomeService"
contract="MySilverlight.Web.SomeServiceReference.ISomeService"
name="BasicHttpBinding_ISomeService" />
</client>
<extensions />
</system.serviceModel>
</configuration>

IIS 7.5 将自动设置您的本地主机证书。

关于Silverlight 4 - 配置自承载 WCF 服务以使用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6063304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com