빠른 시작을 통해 Prism v2를 연구 중입니다.서비스 참조에서 Silverlight 클라이언트를 생성 해제하십시오.
[System.ServiceModel.ServiceContractAttribute
(Namespace="http://helloworld.org/messaging",
ConfigurationName="Web.Services.HelloWorldMessageService")]
public interface HelloWorldMessageService {
[System.ServiceModel.OperationContractAttribute
(AsyncPattern=true,
Action="http://helloworld.org/messaging/HelloWorldMessageService/UpdateMessage",
ReplyAction="http://helloworld.org/messaging/HelloWorldMessageService/UpdateMessageResponse")]
System.IAsyncResult BeginUpdateMessage(string message, System.AsyncCallback callback, object asyncState);
void EndUpdateMessage(System.IAsyncResult result);
[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://helloworld.org/messaging/HelloWorldMessageService/GetMessage", ReplyAction="http://helloworld.org/messaging/HelloWorldMessageService/GetMessageResponse")]
System.IAsyncResult BeginGetMessage(System.AsyncCallback callback, object asyncState);
string EndGetMessage(System.IAsyncResult result);
}
public partial class HelloWorldMessageServiceClient : System.ServiceModel.ClientBase<HelloWorld.Core.Web.Services.HelloWorldMessageService>, HelloWorld.Core.Web.Services.HelloWorldMessageService {
{
// implementation
}
난 : 내 실버 라이트 프로젝트에서이 서비스에 대한 서비스 참조를 추가 할 때 그 인터페이스와 클래스를 생성
namespace HelloWorld.Silverlight.Web
{
[ServiceContract(Namespace = "http://helloworld.org/messaging")]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class HelloWorldMessageService
{
private string message = "Hello from WCF";
[OperationContract]
public void UpdateMessage(string message)
{
this.message = message;
}
[OperationContract]
public string GetMessage()
{
return message;
}
}
}
: 그리고 나는 다음과 같은 서명 WCF 서비스를 만들었습니다 구체적인 클래스 대신 인터페이스를 통과하여 애플리케이션을 분리하려고합니다. 하지만이 작업을 수행하는 방법의 예를 찾는 데 어려움이 있습니다. EndGetMessage를 호출하고 내 UI를 업데이트하면 잘못된 스레드에서 UI를 업데이트하는 예외가 발생합니다. 백그라운드 스레드에서 UI를 업데이트하려면 어떻게해야합니까?
나는 노력하지만
UnauthorizedAccessException : Invalid cross-thread access
를 얻을.
string messageresult = _service.EndGetMessage(result);
Application.Current.RootVisual.Dispatcher.BeginInvoke(() => this.Message = messageresult);
예외는 Application.Current.RootVisual
에 의해 발생합니다.
내가 시도하지만 UnauthorizedAccessException 얻을 : 여기에 최근 그게 내가 마지막으로 모든 것을 처리하는 방법에 대한 내용이수록되어 쓴 글입니다 잘못된 크로스 스레드 액세스. 문자열 messageresult = _service.EndGetMessage (result); Application.Current.RootVisual.Dispatcher.BeginInvoke (() => this.Message = messageresult ); 예외는 Application.Current.RootVisual에 의해 throw됩니다. –