我已经撞墙了,已经把头发拉了一段时间了。基本上,我需要创建一个具有ASP.NET成员资格和授权提供程序的WCF服务,但是它需要允许传输byte []数组或Stream对象并将它们保存到Azure。该服务本身托管在Azure上。
我遇到的问题是WCF需要消息层安全性来交换客户端凭据。所以我有以下配置,它运作得很好:
<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>
然后需求发生变化,现在我需要通过WCF服务将文件推送到Azure。无论我做什么,WCF都会因各种错误而尖叫我。
有谁知道如何配置服务,以便它可以使用身份验证/授权以及流媒体?
谢谢!
答案 0 :(得分:6)
虽然您提供的信息不足以确定问题,但我认为获取错误的原因是由于WCF默认的邮件大小限制,例如邮件,内容和数组长度。
这些设置的默认值太低(maxReceivedMessageSize为64K,maxArrayLength为16K,maxStringContentLength为8K)通过WCF传输大数据,应该增加以便能够处理包含更大数据的消息或字节数组。您可以使用readerQuotas和wsHttpBinding/binding元素更改这些默认值。
以下是基于配置文件的示例设置,允许最多4MB的消息,字符串和字节数组传输。
<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>