티스토리 뷰

반응형

원래 계획과는 좀 다르게 메신저가 되어 가고 있지만, 일단 만들어 보기로 했고, 만들어가는 중간 단계이기 때문에 개발자 레퍼런스 정도로 보면 된다. 자세한 설명은 생략한다.

연결 포스트

WCF RIA Service host SOAP endpoint

http://kaki104.tistory.com/63

Silverlight 5 & WCF RIA Service & SQL CE 4.0

http://kaki104.tistory.com/62

1. Service References 추가
ria service가 호스팅 되고 있는 곳의 주소를 가지고 서비스 레퍼런스를 추가한다.

 


Advanced를 눌러서 Always generate message contracts를 체크 한다. 반환되는 모든 데이터를 ObservableCollection에 담아서 달라는 의미이다.


확인을 눌러서 추가한다.

** 추가 하다가 이런 오류가 나는 경우가 있는데..
Error 6 Custom tool error: Failed to generate code for the service reference 'WP7ServiceReference'.  Please check other error and warning messages for details.

1) 서비스가 실행되고 있지 않는 경우 -> 해당 페이지를 실행 시켜서 서비스를 활성화 시킨 후 다시 시도한다.
2) VS2010 내부에 문제가 있어서 않되는 경우 -> VS2010 종료 후 다시 시작해서 시도한다.

2. 쿠키 사용 추가
How to open a WCF RIA Services application to other type of clients: the SOAP endpoint (3/5)
http://blogs.msdn.com/b/davrous/archive/2010/12/03/how-to-open-a-wcf-ria-services-application-to-other-type-of-clients-the-soap-endpoint-3-5.aspx
위의 포스트 중간 쯤 내려가면 Using the SOAP endpoint from a Windows Phone 7 client 이란 곳이 있다.

그곳에 보면 쿠키 추가하는 부분이 있는데 복사해서 프로젝트의 ServiceReferences.ClientConfig 파일을 열어서 추가한다.

<binding name="BasicHttpBinding_AuthenticationServiceSoap" maxBufferSize="2147483647"
          enableHttpCookieContainer="true"
          maxReceivedMessageSize="2147483647">
    <security mode="None" />
</binding>
<binding name="BasicHttpBinding_BookClubServiceSoap" maxBufferSize="2147483647"
    enableHttpCookieContainer="true"
          maxReceivedMessageSize="2147483647">
    <security mode="None" />
</binding>

** 위의 코드를 추가해 놓으면 Service Reference를 업데이트 하는 도중 오류가 발생한다. 그래서 업데이트를 할때는 살짝 지워 놓고, 업데이트가 끝난 후에 다시 붙여 놓아야 한다. (찾아낸 가장 심플한 대답이였다. ㅋ)
** 쿠키가 있어서 빌드시 오류가 나오는 경우가 있는데..음음..정확한 원인은 아직..그래서 이번 소스에서는 쿠키 제거 했음

3. 윈도우 폰에서 사용하기

  //쿠키 컨테이너
  CookieContainer cookieContainer = null;
  //Soap Client Context
  WP7DomainServiceSoapClient context = null;

...........

  /// <summary>
  /// 생성자
  /// </summary>
  public MainPageViewModel()
  {
      //도메인 서비스 솝 클라이언트
      context = new WP7DomainServiceSoapClient();
      //조회 완료 이벤트 처리
      context.GetWP7UriListSetCompleted += new EventHandler<GetWP7UriListSetCompletedEventArgs>(context_GetWP7UriListSetCompleted);
      //저장 완료 이벤트 처리
      context.SubmitChangesCompleted += new EventHandler<SubmitChangesCompletedEventArgs>(context_SubmitChangesCompleted);
  }

..............


  /// <summary>
  /// 저장 완료 이벤트 처리
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  void context_SubmitChangesCompleted(object sender, SubmitChangesCompletedEventArgs e)
  {
      if (e.Error == null)
      {
          //저장 완료 후 반환된 결과를 받아서
          ObservableCollection<ChangeSetEntry> returnChangeSet = e.Result.SubmitChangesResult;
          //그중 처음 데이터의 오퍼레이션을 확인하고
          var operation = returnChangeSet.FirstOrDefault().Operation;
          //오퍼레이션 종류에 따라 메시지 출력
          switch (operation)
          {
              case DomainOperation.Insert:
                  MessageData = "My channel uri regist successfully";
                  CurrentData = returnChangeSet.FirstOrDefault().Entity as WP7UriList;
                  break;
              case DomainOperation.Update:
                  MessageData = "My channel uri modify successfully";
                  break;
              case DomainOperation.Delete:
                  MessageData = "My channel uri deregist successfully";
                  CurrentData = null;
                  break;
          }
      }
      else
      {
          MessageData = "Error";
      }
  }

................

  //조회 완료시 컬렉션 설정
  void context_GetWP7UriListSetCompleted(object sender, GetWP7UriListSetCompletedEventArgs e)
  {
      WP7Collection = new ObservableCollection<WP7UriList>(e.Result.GetWP7UriListSetResult.RootResults);
  }

...............

  private ICommand addCommand;
  /// <summary>
  /// 추가 커맨드
  /// </summary>
  public ICommand AddCommand
  {
      get
      {
          if (addCommand == null)
          {
              addCommand = new ActionCommand(InputUserName =>
              {
                  //입력 받은 사용자 이름을 확인
                  string userName = InputUserName as string;
                  if (userName != null && userName != "")
                  {
                      //폰의 ChannelUri 확인
                      if (ChannelUri == null && ChannelUri == "")
                      {
                          MessageData = "no chann uri, try again";
                          return;
                      }
                      //새로운 레코드 생성
                      WP7UriList addItem = new WP7UriList
                      {
                          UserName = userName,
                          ChannelUri = ChannelUri,
                          RegDT = DateTime.Now,
                          UptDT = DateTime.Now,
                          UseBT = true
                      };

                      //체인지셋 구성
                      ObservableCollection<ChangeSetEntry> addedItems = new ObservableCollection<ChangeSetEntry>();
                      ChangeSetEntry addChangeSetEntry = new ChangeSetEntry
                      {
                          OriginalEntity = null,
                          Entity = addItem,
                          Operation = DomainOperation.Insert
                      };
                      //체인지셋에 새로만든 레코드 추가
                      addedItems.Add(addChangeSetEntry);
                      //SubmitChangeRequest 생성
                      SubmitChangesRequest request = new SubmitChangesRequest(addedItems);
                      //SubmitChangeAsync 실행
                      context.SubmitChangesAsync(request, this);
                  }
              }
              );
          }
          return addCommand;
      }
  }

kakao 입력 -> Regist 버튼 클릭


실버라이트에서 결과 확인

등록된 kakao를 선택 한 후 Raw Notification 보냄


...................

  private ICommand removeCommand;
  /// <summary>
  /// 삭제 커맨드 - 현재 사용자의 정보를 서버에서 완전히 삭제 한다
  /// </summary>
  public ICommand RemoveCommand
  {
      get
      {
          if (removeCommand == null)
          {
              removeCommand = new ActionCommand(() =>
              {
                  if (CurrentData != null)
                  {
                      //체인지셋 구성
                      ObservableCollection<ChangeSetEntry> removeItems = new ObservableCollection<ChangeSetEntry>();
                      ChangeSetEntry removeChangeSetEntry = new ChangeSetEntry
                      {
                          OriginalEntity = CurrentData,
                          Entity = CurrentData,
                          Operation = DomainOperation.Delete
                      };
                      //체인지셋에 수정할 데이터 입력
                      removeItems.Add(removeChangeSetEntry);
                      //SubmitChangeRequest 생성
                      SubmitChangesRequest request = new SubmitChangesRequest(removeItems);
                      //SubmitChangeAsync 실행
                      soapClient.SubmitChangesAsync(request, this);
                  }
              });
          }
          return removeCommand;
      }
  }

Unregist 버튼 클릭

실버라이트에서 결과 확인


......................

  private ICommand saveCommand;
  /// <summary>
  /// 저장 커맨드 - 현재 사용자의 정보를 업데이트 한다.
  /// </summary>
  public ICommand SaveCommand
  {
      get
      {
          if (saveCommand == null)
          {
              saveCommand = new ActionCommand(() =>
              {
                  if (CurrentData != null)
                  {
                      //현재 데이터 변경
                      CurrentData.UseBT = false;

                      //체인지셋 구성
                      ObservableCollection<ChangeSetEntry> updateItems = new ObservableCollection<ChangeSetEntry>();
                      ChangeSetEntry updateChangeSetEntry = new ChangeSetEntry
                      {
                          OriginalEntity = CurrentData,
                          Entity = CurrentData,
                          Operation = DomainOperation.Update
                      };
                      //체인지셋에 수정할 데이터 입력
                      updateItems.Add(updateChangeSetEntry);
                      //SubmitChangeRequest 생성
                      SubmitChangesRequest request = new SubmitChangesRequest(updateItems);
                      //SubmitChangeAsync 실행
                      soapClient.SubmitChangesAsync(request, this);
                  }
              });
          }
          return saveCommand;
      }
  }

....................

  private ICommand selectCommand;
  /// <summary>
  /// 조회 커맨드 - load button 클릭 시 발생
  /// </summary>
  public ICommand SelectCommand
  {
      get
      {
          if (selectCommand == null)
          {
              selectCommand = new ActionCommand(() =>
              {
                  //조회 함수 호출
                  GetWP7UriListSetRequest request = new GetWP7UriListSetRequest();
                  soapClient.GetWP7UriListSetAsync(request, this);
              });
          }
          return selectCommand;
      }
  }

나머지는 채널 관리하는 소스와, Raw Notification 소스 이다. 이전 포스트에서 이미 다루었던 내용으로 다시 다루지는 않겠다.

WP7NotificationService.zip
다운로드


 

반응형
댓글