2011-08-18 11 views
12

.NET Frameworkのバグを発見したのですか、何か間違っていますか?パスワードにWCFの英国ポンドを含めることはできませんか?

ここにその話があります。

私はそのように昨日WCFチャネル上でパスワードを設定しようとしていた

channelFactory.Credentials.UserName.UserName = credentials.Username; 
channelFactory.Credentials.UserName.Password = credentials.Password; 

、その後、私はこのエラーを得たときに、Webサービスメソッドを呼び出します。

System.ServiceModel.CommunicationException 
    Message=An error (The request was aborted: The request was canceled.) occurred while transmitting data over the HTTP channel. 
    Source=mscorlib 
    StackTrace: 
    Server stack trace: 
     at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) 
     at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
     at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 
     at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) 
     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 
    Exception rethrown at [0]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
     at PocketKings.Tools.Services.PopulationManager.Client.PopulationService.IPopulationService.ResolvePopulationMember(ResolveRealmMemberQuery request) 
    InnerException: System.Net.WebException 
     Message=The request was aborted: The request was canceled. 
     Source=System 
     StackTrace: 
      at System.Net.HttpWebRequest.GetResponse() 
      at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
     InnerException: System.NotSupportedException 
      Message=This method is not supported by this class. 
      Source=System 
      StackTrace: 
        at System.Net.BasicClient.EncodingRightGetBytes(String rawString) 
        at System.Net.BasicClient.Lookup(HttpWebRequest httpWebRequest, ICredentials credentials) 
        at System.Net.BasicClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials) 
        at System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials) 
        at System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo) 
        at System.Net.HttpWebRequest.CheckResubmitForAuth() 
        at System.Net.HttpWebRequest.CheckResubmit(Exception& e) 
        at System.Net.HttpWebRequest.DoSubmitRequestProcessing(Exception& exception) 
        at System.Net.HttpWebRequest.ProcessResponse() 
        at System.Net.HttpWebRequest.SetResponse(CoreResponseData coreResponseData) 

ので、私は探し始めましたそれとログには、私がサーバーのところまで来ることさえないということが示されています。例外(System.Net.BasicClient.EncodingRightGetBytes(String rawString))をスローする.NETフレームワークメソッドは、英ポンド記号(£)を好まないことが判明しました。

私はリフレクタからのメソッドをコピーして、迅速なユニットテストやポンドを書いたが、それは私がキーボードから入力でき、すべてからのようなdoesntのことを唯一の文字である:

internal static byte[] EncodingRightGetBytes(string rawString) 
    { 
      byte[] bytes = Encoding.Default.GetBytes(rawString); 
      string strB = Encoding.Default.GetString(bytes); 

      if (string.Compare(rawString, strB, StringComparison.Ordinal) != 0) 
     { 
      throw ExceptionHelper.MethodNotSupportedException; 
     } 
     return bytes; 
} 

これがチェックするために私のユニットテストですこの方法:

[Test] 
public void test123() 
{ 
     string domain = "localhost"; 
     string userName = "lukk"; 

     string charactersToCheck = @"¬`!£$%^&*()_+={}[]:;@'~#<>,.?/|\"; 

     foreach (var character in charactersToCheck.ToCharArray()) 
     { 
       string internalGetPassword = character.ToString(); 

       try 
       { 
        // begin - this assignement was copied from System.Net.BasicClient.Lookup method 
        byte[] inArray = EncodingRightGetBytes(
          (!string.IsNullOrEmpty(domain) ? (domain + @"\") : "") 
          + userName 
          + ":" 
          + internalGetPassword); 
        //end 
       } 
       catch (Exception ex) 
       { 
        Console.WriteLine(string.Format("this character is bad: {0}", internalGetPassword)); 
       } 
     } 
} 

あなたがEncodingRightGetBytesを見ることができるように2つの文字列を比較して、元の文字列(rawString)は英国ポンドが含まれている場合、彼らは異なっています。

EncodingRightGetBytes私は交換時に正常に動作して...

は、このメソッドの名前をグーグルでは、そのうちの一つが、このことは非常にいくつかのリンクを戻します「Encoding.Defaultを。」「Encoding.UTF8。」: http://support.microsoft.com/kb/943511

私はasp.netプロジェクトに.net 3.5を使用するように設定されたVS 2010を使用しています。

.NET Frameworkのバグか、間違っているのですか?

編集: 私のテストを実行している間、私は、イミディエイトウィンドウでEncoding.Defaultを照会するとき、私はこの取得:

?Encoding.Default 
    {System.Text.SBCSCodePageEncoding} 
    [System.Text.SBCSCodePageEncoding]: {System.Text.SBCSCodePageEncoding} 
    BodyName: "iso-8859-2" 
    CodePage: 1250 
    dataItem: {System.Globalization.CodePageDataItem} 
    decoderFallback: {System.Text.InternalDecoderBestFitFallback} 
    DecoderFallback: {System.Text.InternalDecoderBestFitFallback} 
    EncoderFallback: {System.Text.InternalEncoderBestFitFallback} 
    encoderFallback: {System.Text.InternalEncoderBestFitFallback} 
    EncodingName: "Central European (Windows)" 
    HeaderName: "windows-1250" 
    IsBrowserDisplay: true 
    IsBrowserSave: true 
    IsMailNewsDisplay: true 
    IsMailNewsSave: true 
    IsReadOnly: true 
    IsSingleByte: true 
    m_codePage: 1250 
    m_deserializedFromEverett: false 
    m_isReadOnly: true 
    WebName: "windows-1250" 
    WindowsCodePage: 1250 
+1

英国のキーボードを使用していると仮定すると、文字列の一部として±、§、または€を入力すると(英字のキーボードではすべてが見つかります)、どうなりますか?これらのエラーも同様に失敗すると、これらの文字のすべてが128以上のコード(8ビットを使用)を持つため、問題は7対8ビットエンコーディングであるため、デフォルトエンコーディングでは正しく処理できません。ラテン語1またはその変形です。エンコードをUTF8に変更する方法はありますか? –

+0

ポンド文字が「拡張」ASCII文字としてエンコードされているという問題のように聞こえますが、これは使用されたコードページを知っていれば意味をなすことができます(パスワードハッシュには、それを作る)ので、エンコード方法は、あいまいにエンコードされた文字を正しく拒否している可能性があります。 UTF8は適切なソリューションのように聞こえる。 – David

+0

こんにちは、ご意見ありがとうございます。 @Aleks - これら3つの文字をテスト文字列に追加しました。これらの文字はすべてテストに合格しました。私のキーボードは英語(アイルランド) – lukk

答えて

2

を私はASPと似たような経験しているが、私が使用して問題を回避するために管理しました次の設定。

<system.web>  
<globalization 
fileEncoding="utf-8" 
requestEncoding="utf-8"  
responseEncoding="utf-8" 
culture="en-GB" 
uiCulture="en-GB"/> 
... 

あなたは

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 

を更新したときに、私の知る限りでは、グローバル化タグはWCFのために同じことを動作します。ただ、ページの下部にMSDNをチェックし、それは次のように述べている:

The ASP.NET configuration language allows you to specify the culture for individual services. The WCF does not support that configuration setting except in ASP.NET compatibility mode. To localize a WCF service that does not use ASP.NET compatibility mode, compile the service type into culture-specific assemblies, and have separate culture-specific endpoints for each culture-specific assembly.

関連する問題