4

我有一个使用在 HTTP 中工作的 nettcp 的 Silverlight 4.0 应用程序。然后我尝试从 http 切换到 https。这是我开始遇到问题的地方。当我运行应用程序时,我会收到 Internet Explorer 通知“显示混合内容?”。如果我单击“是”,那么我的应用程序中会收到错误消息:

Could not connect to net.tcp://ServerName:4502/TestService.svc/netTcp. The connection attempt lasted for a time span of 00:00:01.2191219. TCP error code 10013: An attempt was made to access a socket in a way forbidden by its access permissions.. This could be due to attempting to access a service in a cross-domain way while the service is not configured for cross-domain access. You may need to contact the owner of the service to expose a sockets cross-domain policy over HTTP and host the service in the allowed sockets port range 4502-4534.

ClientConfig的如下:

    <configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="NetTcpBinding_ITestService">
          <binaryMessageEncoding />
          <tcpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://ServerName:4502/TestService.svc/netTcp"
        binding="customBinding" bindingConfiguration="NetTcpBinding_ITestService"
        contract="TestServer.ITestService" name="NetTcpBinding_ITestService"/>
    </client>
  </system.serviceModel>
</configuration>
 

我的 Web.config 如下:

 <netTcpBinding>
      <binding name="netTcpBindingConfig">
        <security mode="None" />
      </binding>
    </netTcpBinding>

  </bindings>
  <services>
    <service name="TestService">
      <endpoint address="netTcp" binding="netTcpBinding" bindingConfiguration="netTcpBindingConfig" contract="ITestService" />
      <endpoint address="mex" binding="mexHttpsBinding" name="mex" contract="IMetadataExchange" />
      <host>
      <baseAddresses>
        <add baseAddress="net.tcp://ServerName:4502/TestService.svc" />
        <add baseAddress="https://ServerName/TestService.svc" />
      </baseAddresses>
      </host>
    </service>
  </services>
     

在我的服务器的根目录下,我有一个名为clientaccesspolicy.xml

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

nettcp 通信不需要安全,但应用程序中的其他服务需要安全。是否可以在 HTTPS 托管应用程序中运行 nettcp?

4

0 回答 0