共享DataContract工作者角色/ Web角色

时间:2013-01-04 15:51:34

标签: azure internal web-worker endpoints datacontracts

我有一个Azure Web角色通过内部端点链接到辅助角色,目的是使用辅助角色向Web角色提供数据,保持Web角色与数据库之间的隔离[包含敏感数据]。有一个类库项目,其中包含工作者角色和Web角色都引用的所有必需的数据协定。

在开发环境中,一切都很好,它是一种享受。一旦我上传到Azure,工作者角色就会陷入困境。错误消息是:

Message string  Failed with ExceptionSystem.IO.FileNotFoundException: Could not load file or assembly 'ReadOnly_DC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'ReadOnly_DC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   at System.Signature.GetSignature(SignatureStruct& signature, Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.get_Signature()
   at System.Reflection.RuntimeMethodInfo.GetParameters()
   at System.ServiceModel.Description.ServiceReflector.ValidateParameterMetadata(MethodInfo methodInfo)
   at System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction)
   at System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo& reflectionInfo, Object serviceImplementation)
   at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
   at System.ServiceModel.Description.ContractDescription.GetContract(Type contractType, Type serviceType)
   at System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts)
   at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
   at DA_Worker.WorkerRole.StartWS_Host() in C:\Users\grant.roy\Documents\Visual Studio 2010\Projects\CraigAzure\DA_Worker\WorkerRole.cs:line 80

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
; TraceSource 'WaWorkerHost.exe' event

似乎无法打开Data Contract类库“ReadOnly_DC”。

对ReadOnly_DC的引用设置为copy local,我在所有与Data Contract类库一起使用的引用上尝试“Copy Local”无效。

感谢收到任何建议!

捐赠

2 个答案:

答案 0 :(得分:0)

在解决方案资源管理器中右键单击辅助角色项目时,确保在“项目依赖关系...”中选择了类库。

答案 1 :(得分:0)

好的 - 我无法相信这就是答案,但这就是我开始工作的方式。我将各种类库中的所有逻辑直接移动到我的Worker Role项目中,毫不奇怪,它可以找到所需的各种方法和数据契约,并且工作者角色开始了,好吧,工作!!

为了与Web角色共享“共享”资源,我通过解决方案资源管理器中的“添加现有项目”功能将必要的类[Data Contracts,YubiKey-Class和IWebService本身]添加到Web角色,添加它们是“链接”,而不是拥有文件的重复副本。

因此,这保留了我的[隐藏] woker角色中所有秘密内容[连接字符串和共享存储访问密钥]的分离,这些角色来自我的网络角色,该角色暴露在互联网上。