1
votes

I have hit a wall and have been pulling my hair for quite some time now. Basically, I need to create a WCF service which would have ASP.NET Membership and Authorization providers, however it needs to allow the transfer of byte[] arrays or Stream objects and save them to Azure. The service itself is hosted on Azure.

The problem I have is that WCF wants message layer security for the exchange of client credentials. So i had the following config which works pretty well:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="DefaultServiceBehavior">
        <serviceMetadata httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="SqlRoleProvider" />
          <serviceCredentials>
            <serviceCertificate x509FindType="FindBySubjectName" storeName="My" storeLocation="LocalMachine" findValue="SecureChannelCertificate" />
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"  membershipProviderName="SqlMembershipProvider" />
         </serviceCredentials>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <bindings>
    <wsHttpBinding>
      <binding name="SecureBinding" messageEncoding="Mtom">
        <security mode="Message">
          <message clientCredentialType="UserName" negotiateServiceCredential="true" establishSecurityContext="true" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
</system.serviceModel>

So then the requirements changed and now I am required to push files to Azure via the WCF service. No matter what I do, WCF screams at me with all sorts of errors.

Does anyone know how to configure the service so that it can use authentication/authorization as well as Streaming?

Thanks!

1
Can you post the errors?Taylor Bird

1 Answers

6
votes

Although the information you provided is not sufficient to determine the problem, I think the reason getting errors is due to the WCF default message size limits such as message, content and array length.

Default values for these settings are too low (64K for maxReceivedMessageSize, 16K for maxArrayLength and 8K for maxStringContentLength) to transfer large data via WCF and should be increased to be able to process messages or byte arrays that contain larger data. You can change these default values by using the readerQuotas and wsHttpBinding/binding elements.

Here is a sample settings based on your configuration file to allow up to 4MB message, string and byte array transfer.

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="DefaultServiceBehavior">
        <serviceMetadata httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="SqlRoleProvider" />
          <serviceCredentials>
            <serviceCertificate x509FindType="FindBySubjectName" storeName="My" storeLocation="LocalMachine" findValue="SecureChannelCertificate" />
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"  membershipProviderName="SqlMembershipProvider" />
         </serviceCredentials>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <bindings>
    <wsHttpBinding>
      <binding name="SecureBinding" messageEncoding="Mtom" maxReceivedMessageSize="4194304">
<readerQuotas maxStringContentLength="4194304" maxArrayLength="4194304"/>
        <security mode="Message">
          <message clientCredentialType="UserName" negotiateServiceCredential="true" establishSecurityContext="true" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
</system.serviceModel>