SecurityError when calling a HTTPS-WCF Service from Silverlight 4

*爱你&永不变心* 提交于 2019-12-04 05:20:17

问题


I have created a simple WCF-Service which I want to be accessible via https. The WCF-Service uses a UserNamePasswordValidator, customBinding and UserNameOverTransport as authentication mode. I run it in the IIS7.5 where I have created a self-signed server certificate.

I try to connect to that service with an Silverlight 4 application. I create a Service Reference in my Silverlight 4 app, and VS 2010 automatically creates the needed code (so obviously it is able to connect to the service and get the information).

When I call the WCF, I get a SecurityException with no infos about the reason.

I have fiddler running to see what is happening.

GET https://my.server:8099/clientaccesspolicy.xml 404 Not Found (text/html)
GET https://my.server:8099/crossdomain.xml 200 OK (text/xml)

So the GET for the crossdomain.xml seems to be the last call to the server.

The crossdomain.xml looks as follows:

<?xml version="1.0"?> 
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>  
  <allow-access-from domain="*" />  
  <allow-http-request-headers-from domain="*" headers="*" />
</cross-domain-policy>

The exception happens, when base.EndInvoke(...) is called on the client and the ExceptionMessage is the following:

{System.Security.SecurityException ---> System.Security.SecurityException: Sicherheitsfehler bei System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) bei System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClass5.b_4(Object sendState) bei System.Net.Browser.AsyncHelper.<>c_DisplayClass2.b_0(Object sendState) --- Ende der internen Ausnahmestapelüberwachung --- bei System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) bei System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) bei System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}

Here is my UserNamePasswordValidator. Note, that included a logger for debugging reasons. Strange thing is, that the logger never writes anything, so it seems, that the Validate function isn't even called.

namespace ServiceConfiguratorDataSource
{
  public class UserCredentialsValidator : UserNamePasswordValidator
  {
    public override void Validate(string userName, string password)
    {
      if (userName != "xyz" || password != "xyz")
      {
        logging.Logger.instance.StatusRoutine("LogOn Error: " + userName);
        throw new FaultException("Credentials are invalid");
      }
      else
      {
        logging.Logger.instance.StatusRoutine("LogOn Success: " + userName);
      }
    }
  }
}

Here is the Web.config of my WCF-Service:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
      <services>
        <service name="ServiceConfiguratorDataSource.Service" behaviorConfiguration="ServiceConfiguratorDataSourceBehaviour">
          <endpoint address="" binding="customBinding" bindingConfiguration="ServiceConfiguratorCustomBinding" contract="ServiceConfiguratorDataSource.IService" />
        </service>
      </services>
      <bindings>
        <customBinding>
          <binding name="ServiceConfiguratorCustomBinding">
            <security authenticationMode="UserNameOverTransport"></security>
            <binaryMessageEncoding></binaryMessageEncoding>
            <httpsTransport/>
          </binding>
        </customBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior name="ServiceConfiguratorDataSourceBehaviour">
            <serviceMetadata httpsGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="true"/>
            <serviceCredentials>
              <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="ServiceConfiguratorDataSource.UserCredentialsValidator,ServiceConfiguratorDataSource" />
            </serviceCredentials>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
  </configuration>

and here the ServiceReferences.ClientConfig

<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="CustomBinding_IService">
          <security authenticationMode="UserNameOverTransport" includeTimestamp="true">
            <secureConversationBootstrap />
          </security>
          <binaryMessageEncoding />
          <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://my.server:8099/ServiceConfiguratorDataSource/Service.svc" binding="customBinding" bindingConfiguration="CustomBinding_IService" contract="WCFDataProvider.IService" name="CustomBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>

I'm out of ideas what might be the cause of the problem.

Thanks in advance,
Frank


回答1:


Does you clientaccesspolicy.xml allow https?
Here is example.




回答2:


The working clientaccesspolicy.xml -> Tipp from Samvel Siradeghyan

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


来源:https://stackoverflow.com/questions/4086589/securityerror-when-calling-a-https-wcf-service-from-silverlight-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!