Я пытался следовать этот пример (скачайте исходный код по ссылке на сайте или здесь, но я продолжаю сталкиваться с ошибкой, которая, кажется, встроена в пример.
Моя процедура была следующей (после установки AppFabric SDK и других зависимостей):
- Скачать исходный код
- Создайте пространство имен службы в AppFabric.
- Импортируйте проект в новый проект Windows Azure с одной рабочей ролью, убедитесь, что все это компилируется и что метод Run() рабочей роли по умолчанию запускается и работает.
- Настройте метод GetInterRoleCommunicationEndpoint в InterRoleCommunicationExtension.cs с ServiceNameSpace и IssuerSecret из моего пространства имен службы AppFabric (IssuerName и ServicePath остаются по умолчанию). Это жесткое подключение моих собственных параметров.
- Скопируйте/вставьте логику инициализации из файла «SampleWorkerRole.cs» в демо-версии в метод OnStart() рабочей роли моего проекта.
- Закомментируйте ссылки на Tracemanager.*, поскольку в демонстрационном коде методы Tracemanager не реализованы и они не имеют решающего значения для работы этого теста. Таких ссылок около 7-10 (просто выполните Find -> «Tracemanager» во всем решении).
- Стройте успешно.
- Запустите на локальном эмуляторе вычислений.
When I run this test, during the initialization of a new InterRoleCommunicationExtension (the first piece of the inter-role communication infrastructure to be initialized, this.interRoleCommunicator = new InterRoleCommunicationExtension();
), an error is raised: "Value cannot be null. Parameter name: contractType."
Drilling into this a bit, I follow the execution down to the following method in ServiceBusHostFactory.cs (one of the files from the sample):public static Type GetServiceContract(Type serviceType)
{
Guard.ArgumentNotNull(serviceType, "serviceType");
Type[] serviceInterfaces = serviceType.GetInterfaces();
if (serviceInterfaces != null && serviceInterfaces.Length > 0)
{
foreach (Type serviceInterface in serviceInterfaces)
{
ServiceContractAttribute serviceContractAttr = FrameworkUtility.GetDeclarativeAttribute<ServiceContractAttribute>(serviceInterface);
if (serviceContractAttr != null)
{
return serviceInterface;
}
}
}
return null;
}
The serviceType parameter's Name property is "IInterRoleCommunicationServiceContract," which is one of the classes of the demo, and which extends IObservable. The call to serviceType.GetInterfaces() returns the "System.IObservable`1" interface, which is then passed into FrameworkUtility.GetDeclarativeAttribute(serviceInterface);
, which has the following code:
public static IList GetDeclarativeAttributes(Type type) where T : class
{
Guard.ArgumentNotNull(type, "type");
object[] customAttributes = type.GetCustomAttributes(typeof(T), true);
IList<T> attributes = new List<T>();
if (customAttributes != null && customAttributes.Length > 0)
{
foreach (object customAttr in customAttributes)
{
if (customAttr.GetType() == typeof(T))
{
attributes.Add(customAttr as T);
}
}
}
else
{
Type[] interfaces = type.GetInterfaces();
if (interfaces != null && interfaces.Length > 0)
{
foreach (object[] customAttrs in interfaces.Select(iface => iface.GetCustomAttributes(typeof(T), false)))
{
if (customAttrs != null && customAttrs.Length > 0)
{
foreach (object customAttr in customAttrs)
{
attributes.Add(customAttr as T);
}
}
}
}
}
return attributes;
}</code><br>
It is here that the issue arises. After not finding any customAttributes on the "IObservable1" type, it calls type.GetInterfaces(), expecting a return. Even though type is "System.IObservable1," this method returns an empty array, which causes the function to return null and the exception with the above message to be raised.
Я чрезвычайно заинтересован в том, чтобы этот сценарий работал, так как я думаю, что парадигма обмена сообщениями публикации/подписки является идеальным решением для моего приложения. Кто-нибудь смог заставить этот демо-код (от самой команды AppFabric CAT!) работать или может обнаружить мою ошибку? Спасибо за помощь.