2012年2月28日火曜日

非同期呼び出しは既に進行中です。このメソッドを呼び出す前に、処理を完了させるか、またはキャンセルしなければなりません。

昔作ったアプリで下記のエラーが発生しました。
あれれ?と思い、過去のパソコン(WindowsXPx86 Pentium M)を引っ張りだし、テストすると動作する。
どうやら、Windows7x64(Core i7)では発生するエラーのようだ。


日本語:非同期呼び出しは既に進行中です。このメソッドを呼び出す前に、処理を完了させるか、またはキャンセルしなければなりません。
English translation: An asynchronous call is already in progress. It must be completed or canceled before you can call this method.
しくしく、仕方なしに処理の内容をlockステートメントを使用して直列化して対応した。

例)

lock(_smtp)
smtp.Send(...);

lock(_ping)

dic.Value.PingReply = _timeOut != 0 ? _ping.Send(dic.Key, _timeOut) : _ping.Send(dic.Key);

2012年2月6日月曜日

Galaxy S2 SⅡ(SC-02C)が低温で液晶に横線が入る

私の使っているギャラクシーS2は、温度が下がると
下のほうから、
・液晶に横線が入る。


↓さらに寒くなる
・表示データが更新されなくなる
↓さらに寒くなると
・画面が黒くなる
という現象に悩まされています。

先日、docomoショップに持ち込んだところ、
ハードウェアが毎、変更してくれるということですが、
内臓メモリデータは移行してくれないとのことです。

とりあえず、それだと困るので、交換はパスしてきました。
う~ん。
有機液晶ELは温度に弱いのかなぁ?

2012年2月2日木曜日

clientaccesspolicy.xml ファイルを使用して複数ドメイン間のアクセスを許可するには

1)サービスがホストされるドメインのルートに clientaccesspolicy.xml ファイルを配置して、複数ドメイン間アクセスを許可するようにサービスを構成します。
2)サービスがホストされるドメインのルートに有効な crossdomain.xml ファイルを配置します。このファイルでは、ドメイン全体をパブリックに指定する必要があります。
1)の場合、新たに作成した「WCFサービス」のルートに「clientaccesspolicy.xml」ファイルを作成し、下記の内容にすることで各サーバから配信されるSilverlightアプリからアクセスできるようになりました。

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
 <cross-domain-access>
  <policy>
   <allow-from http-request-headers="SOAPAction">
    <domain uri="*"/>
   </allow-from>
   <grant-to>
    <resource path="/" include-subpaths="true"/>
   </grant-to>
  </policy>
 </cross-domain-access>
</access-policy>

2011年7月25日月曜日

RIAServiceでパスワードを送る場合の属性

アプリケーションが安全にサーバのエンドポイントにアクセスするために、ユーザ名とパスワードを送るときは、httpsを使用して渡す必要があります。
そのためには、EnableClientAccessAttribute で RequiresSecureEndpoint プロパティを true に設定する必要があります。

例)
 /// <summary>
 /// ドメイン サービスはユーザーの登録を行います。
 /// </summary>
 [EnableClientAccess(RequiresSecureEndpoint=true)]
 public class UserRegistrationService : DomainService
 {
  /// <summary>
  /// ユーザーが既定で追加されるロールです。
  /// </summary>

SilverlightでのXMLファイルの読み込み

ブラウザでのXMLファイルの読み込み
   //設定ファイルを読み込み
   WebClient client = new WebClient();
   client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
   Uri xmlUri = new Uri(Application.Current.Host.Source, "../Props/aFrameworkSettings.xml");
   client.DownloadStringAsync(xmlUri);
  string xml;
  void  client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  {
   //処理終了
   if (e.Error == null)
   {
    xml = e.Result;
    //このあとxmlを解析する
   }
  }

2011年3月19日土曜日

TripleDESのサンプル



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
using System.Diagnostics;
namespace TripleDESWindowsFormsApplication
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }
  private void _buttonDecrypt_Click(object sender, EventArgs e)
  {
   string source = _textResult.Text;
   string key = _textKey.Text;
   byte[] b = Convert.FromBase64String(source);
   TribleDES tdes = new TribleDES(Encoding.ASCII, 24);
   byte[] v = tdes.Decrypt(b, key);
   //仕様は全てASCII
   WriteDebug(Encoding.ASCII.GetString(v));
  }
  private void _buttonEncrypt_Click(object sender, EventArgs e)
  {
   string source = _textValue.Text;
   string key = _textKey.Text;
   byte[] b = Encoding.ASCII.GetBytes(source);
 
   TribleDES tdes = new TribleDES(Encoding.ASCII, 24);
   byte[] v = tdes.Encrypt(b, key);
   //byte[]を直接Base64へ変換
   string ret = Convert.ToBase64String(v);
    
   WriteDebug(ret);
  }
  void WriteDebug(string msg)
  {
   StringBuilder sb = new StringBuilder();
   sb.Append(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
   sb.Append(":");
   sb.Append(msg);
   sb.AppendLine();
   Debug.WriteLine(sb.ToString());
   _textDebug.Text +=  sb.ToString();
  }
  public class TribleDES
  {
   Encoding _enc;
   int _keySIze;
   public TribleDES(Encoding enc, int keySize)
   {
    _enc = enc;
    _keySIze = keySize;
   }
   public byte[] Encrypt(byte[] source, string key)
   {
    //TripleDESだけど全てキーが同じです。
    // Tripe DES のサービス プロバイダを生成します
    TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
    tDes.KeySize = _keySIze * 8;//192; //192bit 24byte KeySize
    byte[] keyBin = _enc.GetBytes(key); //GenerateKey(key, tDes.Key.Length);
    byte[] iv = _enc.GetBytes(key); //GenerateKey(key, tDes.IV.Length);
    // 入出力用のストリームを生成します
    MemoryStream ms = new MemoryStream();
    CryptoStream cs = new CryptoStream(ms,
     tDes.CreateEncryptor(keyBin, iv), CryptoStreamMode.Write);
    // ストリームに暗号化されたデータを書き込みます
    cs.Write(source, 0, source.Length);
    cs.Close();
    // 復号化されたデータを byte 配列で取得します
    byte[] destination = ms.ToArray();
    ms.Close();
    // byte 配列を文字列に変換して表示します
    //return _enc.GetString(destination);
    return destination;
   }
   public byte[] Decrypt(byte[] source, string key)
         {
    // Tripe DES のサービス プロバイダを生成します
    TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
    tDes.KeySize = _keySIze * 8;//192; //最大 192bit 24byte KeySize
    byte[] keyBin = _enc.GetBytes(key); //GenerateKey(key, tDes.Key.Length);
    byte[] iv = _enc.GetBytes(key); //GenerateKey(key, tDes.IV.Length);
    // 入出力用のストリームを生成します
    MemoryStream ms = new MemoryStream();
    CryptoStream cs = new CryptoStream(ms,
     tDes.CreateDecryptor(keyBin, iv), CryptoStreamMode.Write);
    // ストリームに暗号化されたデータを書き込みます
    cs.Write(source, 0, source.Length);
    cs.Close();
    // 復号化されたデータを byte 配列で取得します
    byte[] destination = ms.ToArray();
    ms.Close();
    // byte 配列を文字列に変換して表示します
    //return _enc.GetString(destination);
    return destination;
        }
  }
  public class Base642String
  {
   private Encoding enc;
   public Base642String(string encStr)
   {
    enc = Encoding.GetEncoding(encStr);
   }
   public string Encode(string str)
   {
    return Convert.ToBase64String(enc.GetBytes(str));
   }
   public string DecodeString(string str)
   {
    return enc.GetString(Convert.FromBase64String(str));
   }
   public byte[] DecodeByte(string str)
   {
    return Convert.FromBase64String(str);
   }
  }

 }
}

2011年3月11日金曜日

エラー 2 The derived entity type 'User' must be declared in a KnownTypeAttribute on the root entity 'AbstractUser'. HogeHogeProjectが発生した。

⇒これは、WCF RIA Serviceで、継承関係にあるUserモデルとAbstractUserモデルの両方を公開したために、Silverlight側でコードがジェネレイトできずにエラーとなってしまった。