Silverlight 在CRM 2011中通过SOAP服务获取OptionSetValue的标签
我有一个Silverlight应用程序,它需要从活动实体获取OptionSetValue属性的标签。属性逻辑名称为activitytypecode,我使用以下扩展方法检索属性元数据:Silverlight 在CRM 2011中通过SOAP服务获取OptionSetValue的标签,silverlight,dynamics-crm-2011,Silverlight,Dynamics Crm 2011,我有一个Silverlight应用程序,它需要从活动实体获取OptionSetValue属性的标签。属性逻辑名称为activitytypecode,我使用以下扩展方法检索属性元数据: public static void RetrieveAttribute(this IOrganizationService service, string entityLogicalName, string entityAttributeName, Action<Or
public static void RetrieveAttribute(this IOrganizationService service,
string entityLogicalName, string entityAttributeName,
Action<OrganizationResponse> callback)
{
var retrieveAttributeRequest = new OrganizationRequest()
{
RequestName = "RetrieveAttribute",
};
retrieveAttributeRequest["EntityLogicalName"] = entityLogicalName;
retrieveAttributeRequest["RetrieveAsIfPublished "] = false;
retrieveAttributeRequest["LogicalName"] = entityAttributeName;
service.BeginExecute(retrieveAttributeRequest,
result =>
{
if (result.IsCompleted)
{
var response = service.EndExecute(result);
callback(response);
}
}, null);
}
我能够调试该过程,但它在var response=service.EndExecute(结果)行失败在我的扩展方法中。我收到以下异常消息:
远程服务器返回错误:NotFound
以下是StackTrace,如果您觉得它很有用:
{System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)
{System.ServiceModel.CommunicationException:远程服务器返回错误:NotFound。-->System.Net.WebException:远程服务器返回错误:NotFound。-->System.Net.WebException:远程服务器返回错误:NotFound。
位于System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
在System.Net.Browser.BrowserHttpWebRequest.c__DisplayClass5.b__4(对象发送状态)中
在System.Net.Browser.AsyncHelper.c__DisplayClass4.b__1(对象发送状态)中
非常感谢您的帮助和指导,谢谢!除了匿名方法之外,以下方法对我有效。请注意MetadataId
private void StartGetAttributeMetadata()
{
OrganizationRequest request = new OrganizationRequest() { RequestName = "RetrieveAttribute" };
request["EntityLogicalName"] = "activitypointer";
request["LogicalName"] = "activitytypecode";
request["MetadataId"] = Guid.Empty;
request["RetrieveAsIfPublished"] = true;
IOrganizationService service = SOAPServerUtility.GetSoapService();
service.BeginExecute(request, new AsyncCallback(EndGetAttributeMetadata), service);
}
private void EndGetAttributeMetadata(IAsyncResult result)
{
OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result);
}
非常感谢,这样做对我来说很有效。我没有尝试这样做,因为我认为这是不相关的,因为他们都做相同的事情,只是用不同的方式。我不能使用匿名方法来做这件事很糟糕,而且我不知道为什么用这种方式做时SOAP上下文会失控。我现在别无选择,只能写一个bunc我讨厌为每个请求使用单独的事件处理程序,因为这会使阅读代码变得更加困难。再次感谢你,这让我疯狂了好几个小时。
private void StartGetAttributeMetadata()
{
OrganizationRequest request = new OrganizationRequest() { RequestName = "RetrieveAttribute" };
request["EntityLogicalName"] = "activitypointer";
request["LogicalName"] = "activitytypecode";
request["MetadataId"] = Guid.Empty;
request["RetrieveAsIfPublished"] = true;
IOrganizationService service = SOAPServerUtility.GetSoapService();
service.BeginExecute(request, new AsyncCallback(EndGetAttributeMetadata), service);
}
private void EndGetAttributeMetadata(IAsyncResult result)
{
OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result);
}