2013年5月23日 星期四

ASP.NET 半形/全形轉換問題

客戶這邊有一個UTF-8編碼的資料,程式必須將抛出的資料由半型轉全形,
但今天客戶確發現有一個字"咏"居然變"?"

原本我們是這樣寫的:
value = Strings.StrConv(value, VbStrConv.Narrow, 0).Trim();
取得的value不管怎麼改,如編為UTF-8都還是無法顯示,

結果找到charles大大的blog
http://charlesbc.blogspot.tw/2007/03/wq.html之後

試著把LocationID改為中國簡體,結果居然可以了!
雖然我還不知道為什麼,但至少先解決了我的問題,
不知道是不是使用LocationId為0時會把原有的UTF-8編碼改掉。




2013年5月16日 星期四

SilverLight連接WCF使用Windows驗證

環境: Windows Server 2008 R2
1.伺服器的"驗證"必須將Windows驗證開啟,並關閉匿名驗證。
2.設定Application為"整合式",進入進階段定後將"識別"改為Network Service。
3.設定Web.Config的<system.serviceModel>區塊

<system.serviceModel>
<services>
<service name="MT.WebApp.InsuranceService" behaviorConfiguration="asdf">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpBinding" contract="MT.WebApp.IInsuranceService" />
</service>
</services>

<diagnostics>
<endToEndTracing activityTracing="true" messageFlowTracing="true" propagateActivity="true"></endToEndTracing>
</diagnostics>

<bindings>
<basicHttpBinding>
<binding name="httpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>

<behaviors>
<serviceBehaviors>
<behavior name="asdf">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
<serviceDebug  includeExceptionDetailInFaults="true" />

</behavior>
</serviceBehaviors>
</behaviors>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"  multipleSiteBindingsEnabled="false"/>
</system.serviceModel>

4.設定Silver config檔。

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IInsuranceService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
<endpoint address="http://localhost/WebETOS/InsuranceService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInsuranceService"
                contract="ServiceReference.IInsuranceService" name="BasicHttpBinding_IInsuranceService" />

</client>
    </system.serviceModel>
</configuration>