我試圖從Silverlight(v5)中使用BasicHTTPBinding WCF服務(它是自託管在.Net 4.0控制檯應用程序中)。當沒有傳輸加密時,這一切都可以正常工作,但我希望將流量包裝在一層SSL中。不需要任何形式的認證。使用BasicHTTPBinding Silverlight中的WCF服務在打開安全性時中斷
傳輸安全性打開時,我得到的內部異常
{System.Security.SecurityException ---> System.Security.SecurityException:安全錯誤。在 System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)at System.Net.Browser.BrowserHttpWebRequest。 <> c_ DisplayClassa.b _9(Object sendState)at System.Net.Browser.AsyncHelper。 <> C_ DisplayClass4.b _0(對象 sendState)---內部異常堆棧跟蹤的末尾在 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,對象狀態)在System.Net。 Browser.BrowserHttp WebRequest.EndGetResponse(IAsyncResult的asyncResult)在 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);
clientaccesspolicy.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-headers
到https-request-headers
無濟於事。
任何人都可以看到有什麼問題;在BasicHTTPBinding上啓用簡單的SSL安全性需要做什麼?
您的服務器是否提供完全有效的(!)安全證書?嘗試使用https在瀏覽器中打開服務網址,並檢查瀏覽器警告。 – nvoigt 2013-04-10 14:09:33
對不起,應該補充說:是的,有一個合適的有效證書綁定到*:8080。 – KenD 2013-04-10 14:14:38
您可以構建一個小型控制檯應用程序並在那裏測試連接嗎? Silverlight對它認爲有效的證書非常挑剔(!)。 – nvoigt 2013-04-10 14:27:15