Silverlight 4 - 配置自托管 WCF 服务以使用 SSL

发布于 2024-11-08 16:29:20 字数 2192 浏览 0 评论 0原文

我有一个在同一服务器(自托管)上使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当梦初醒 2024-11-15 16:29:20

有几点:

如果您想在本地主机上使用 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 将自动设置您的本地主机证书。

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:

<?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>

Example server-side 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>

Example client-side:

<?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 will setup your localhost certificate automatically.

甜味超标? 2024-11-15 16:29:20

您可以更新客户项目上的服务参考吗?这应该使用正确的绑定更新 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文