0

我正在尝试使用 Silverlight (v5) 中的 BasicHTTPBinding WCF 服务(在 .Net 4.0 控制台应用程序中自托管)。当没有传输加密时,一切正常,但我想将流量包装在 SSL 层中。不需要任何类型的身份验证。

打开传输安全性后,我得到了内部异常

{System.Security.SecurityException ---> System.Security.SecurityException:安全错误。在 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在 System.Net.Browser.BrowserHttpWebRequest.<>c_ DisplayClassa.b _9(Object sendState) 在 System.Net.Browser.AsyncHelper.<>c_ DisplayClass4.b _0 (Object sendState) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Browser.BrowserHttp WebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) 在 System .ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult 结果)}

这是代码:

服务器 - 不工作(有安全性)

baseAddress = new Uri("https://mysite.com:8080/myService"); 
BasicHttpBinding externalBinding = new BasicHttpBinding{                                                              MaxReceivedMessageSize = 1000000,
MaxBufferPoolSize = 1000000,
SendTimeout = TimeSpan.FromSeconds(30),
ReceiveTimeout = TimeSpan.FromSeconds(30),
Security = {Mode = BasicHttpSecurityMode.Transport}                                          
                                                   };

           externalBinding.Security.Transport.ClientCredentialType=HttpClientCredentialType.None;
host.AddServiceEndpoint(typeof(IPolicyRetriever), wsbinding, "").Behaviors.Add(new WebHttpBehavior());
host.AddServiceEndpoint(typeof(ImyServiceService), externalBinding, "myService");

服务器工作(没有安全性)

baseAddress = new Uri("http://mysite.com:8080/myService"); 

BasicHttpBinding externalBinding = new BasicHttpBinding
{
MaxReceivedMessageSize = 1000000,
MaxBufferPoolSize = 1000000,
SendTimeout = TimeSpan.FromSeconds(30),
ReceiveTimeout = TimeSpan.FromSeconds(30)
                                   }    ;

host.AddServiceEndpoint(typeof(IPolicyRetriever), wsbinding, "").Behaviors.Add(new WebHttpBehavior());
host.AddServiceEndpoint(typeof(ImyServiceService), externalBinding, "myServiceService");

SL 客户端不工作(有安全性)

EndpointAddress address = new EndpointAddress("https://mysite.com:8080/myService");
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);                                  
client = new myServiceServiceReference.myServiceServiceClient(binding, address);

SL 客户端工作(无安全性)

EndpointAddress address = new EndpointAddress("http://mysite.com:8080/myService");
BasicHttpBinding binding = new BasicHttpBinding();                           
client = new myServiceServiceReference.myServiceServiceClient(binding, address);

客户端访问策略.xml

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

我试过改http-request-headershttps-request-headers没用。

任何人都可以看到有什么问题吗?我需要做什么才能在此 BasicHTTPBinding 上启用简单的 SSL 安全性?

4

1 回答 1

1

破解它。奇怪的是,问题出<domain uri=""*""/>clientaccesspolicy.xml文件中的那一行——对于 SSL,它必须明确包含 HTTPS。所以工作文件看起来像:

<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""/>
    </grant-to>
   </policy> 
  </cross-domain-access>
</access-policy>

奇怪,但显然是真的。

于 2013-04-10T15:43:20.870 回答