2011-08-18 11 views
12

.NET çerçevesinde bir hata buldum mu yoksa yanlış bir şey mi yapıyorum?Şifre WCF'de İngiliz Pound'u içeremez mi?

İşte hikaye.

Ben böyle WCF kanalında bir şifre dün ayarlamak çalışıyordum:

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) 

Yani ben bakmaya başladı: Ben bu hatayı aldığımda web hizmeti yöntemi çağırmak sonra

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

ve o ve günlükler sunucuya kadar bile ulaşamadığımı gösteriyor. Bir istisna atar .NET framework yöntemi, (System.Net.BasicClient.EncodingRightGetBytes (String rawString)), İngiliz sterlini işareti (£) sevmiyor ortaya çıkıyor.

ben reflektör dan yöntemini kopyalanan ve hızlı ünite testi yazıp kiloluk tüm bir klavye üzerinde yazabilirsiniz gibi doesnt tek karakterdir: Bu kontrol etmek benim birim test

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; 
} 

olduğunu bu yöntem:

[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)); 
       } 
     } 
} 

sen EncodingRightGetBytes Görüldüğü gibi iki dizeyi karşılaştırır ve orijinal dize (rawString) ingiliz kiloluk içeriyorsa bunlar farklı. Ben değiştirdiğinizde

EncodingRightGetBytes çalışıyor ile ...

bunlardan biri bu varlık, bu yöntem adı çok az sayıda bağlantı geri getiriyor google'da “Encoding.Default.” “Encoding.UTF8.”: http://support.microsoft.com/kb/943511

VS 2010'u .net 3.5 kullanacak bir asp.net projesiyle kullanıyorum.

Bu, .NET çerçevesindeki bir hata mı yoksa yanlış bir şey mi yapıyorum?

Düzenleme: testimi çalışırken ben hemen penceresinde Encoding.Default sorgulamak zaman bu olsun:

Ben asp ile benzer bir şey yaşadım
?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

Bir ingilizce klavyeyi kullandığınızı varsayarsak, dizenin bir parçası olarak ±, § veya € girerseniz ne olur (hepsi İngiltere klavyesinde bulunur)? Eğer bunlar da başarısız olursa, o zaman bu karakterlerin tümü 8'den 8 bit kodlamaya sahiptir, çünkü tüm bu karakterlerin 128'in üzerinde kodları vardır (yani 8 bit kullanır) ve bu nedenle varsayılan kodlamayla doğru şekilde işlenemezler. , Latin1 veya bunun bir çeşitlemesidir. Kodlamayı UTF8 olarak değiştirmenin bir yolu var mı? –

+0

Bir 'genişletilmiş' ASCII karakteri olarak kodlanan pound karakteriyle ilgili bir sorun gibi geliyor, bu da yalnızca kullanılan kod sayfasını biliyorsanız anlam kazanabilir (açıkçası bir şifre karması kullanılan kod sayfasını içermez Bunu yapmak için kodlama yöntemi, doğrulanmamış kodlanmış karakterleri haklı olarak reddedebilir. UTF8 doğru çözüm gibi geliyor. – David

+0

Merhaba arkadaşlar, yorumlarınız için teşekkür ederiz. @Aleks - Bu üç karakteri ekledim: "± § €" test dizilimime ve hepsi de testi geçsin. BTW klavyem İngilizcedir (İrlanda) – lukk

cevap

2

, ben yönetilen kullanarak soruna almak aşağıdaki yapılandırma. Eğer

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 

Güncelleme set küreselleşme etiketi WCF için aynı şekilde çalışır Bildiğim kadarıyla

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

:

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.

: Sadece aşağıdaki bildiren sayfanın alt kısmında MSDN kontrol