Analytics

顯示具有 WCF 標籤的文章。 顯示所有文章
顯示具有 WCF 標籤的文章。 顯示所有文章

2014年10月1日 星期三

[XML]解決 An Invalid character was found in text content. (Resolve An Invalid character was found in text content.)


問題
An Invalid character was found in text content.



解決方法
The following are the character ranges for low-order non-printable ASCII characters that are rejected by MSXML versions 3.0 and later:

#x0 - #x8 (ASCII 0 - 8)
#xB - #xC (ASCII 11 - 12)
#xE - #x1F (ASCII 14 - 31)
以上定義說明了在XML理不支援的ASCII,因此解決方式有2種: 先將不支援的ASCII列出
Private Function AsciiLowOrderList() As List(Of Char)
        Dim filter As List(Of Char) = New List(Of Char)
        For i As Integer = 0 To 31
            If i <> 9 Or i <> 10 Or i <> 13 Then
                filter.Add(Chr(i))
            End If
        Next

        Return filter

    End Function
1.轉成CHAR,再逐一比對
    Private Function AsciiLowOrderFilterByChr(ByVal strVal As String) As String
        Dim chrs As Char() = strVal.ToCharArray()

        Dim buffer As StringBuilder = New StringBuilder(strVal.Length)

        Dim filter As List(Of Char) = AsciiLowOrderList()
        For Each chr As Char In chrs
            If filter.Contains(chr) = False Then
                buffer.Append(chr)
            End If
        Next

        Return buffer.ToString()
    End Function
2.採用REPLACE方式避開此問題
    Private Function AsciiLowOrderFilterByReplace(ByVal strVal As String) As String
        For Each chr As Char In AsciiLowOrderList()
            strVal = strVal.Replace(chr,string.Empty)
        Next

        Return strVal

    End Function

2012年3月3日 星期六

[WCF]解決 WCF下呼叫WMI發生存取被拒。 (發生例外狀況於 HRESULT: 0x80070005 (E_ACCESSDENIED)) (Resolve WCF WMI happen next call access denied. (Exceptions occur in HRESULT: 0x80070005 (E_ACCESSDENIED)))


問題
WCF下呼叫WMI發生存取被拒。
在使用WMI開發遠端存取的功能時,都很順利,但當把程式碼移到WCF裡,部屬到IIS後,就無法存取了!
起先試過把ApplicationPool的執行身分改為LocalSystem/LocalService/NetworkService測試過都不行




解決方法
指定IIS機器上的使用者名稱與密碼!

2011年12月15日 星期四

[WCF,WebService]比較 WCF wsHttpbinding,netTcpBinding vs WebService 速度(Compare WCF wsHttpbinding, netTcpBinding vs WebService speed)


問題
WCF wsHttpbinding,netTcpBinding vs WebService 速度



解決方法
基準:
66萬筆資料塞入弱型別DataSet回傳
結果表示:
Client --> Middle(指令從client端傳入service時的時間,可以說是open connection的時間)
Middle --> Clien(從db取得資料以後,回傳到client所需時間)
WCF wsHttpbinding VS WebService
WCF WebService
ROUND 1 Client --> Middle : 946
Middle --> Client : 270615
Client --> Middle : 968
Middle --> Client : 19831
ROUND 2 Client --> Middle : 835
Middle --> Client : 33100
Client --> Middle : 957
Middle --> Client : 19883
ROUND 3 Client --> Middle : 878
Middle --> Client : 29743
Client --> Middle : 955
Middle --> Client : 19832
ROUND 4 Client --> Middle : 778
Middle --> Client : 289066
Client --> Middle : 953
Middle --> Client : 19690
ROUND 5 Client --> Middle : 694
Middle --> Client : 320080
Client --> Middle : 954
Middle --> Client : 19868
ROUND 6 Client --> Middle : 963
Middle --> Client : 28066
Client --> Middle : 960
Middle --> Client : 19713
AVG Client --> Middle : 867
Middle --> Client : 34653
Client --> Middle : 957
Middle --> Client : 19802

WCF netTCPbinding VS WebService
WCF WebService
ROUND 1 Client --> Middle : 841
Middle --> Client : 19025
Client --> Middle : 968
Middle --> Client : 19831
ROUND 2 Client --> Middle : 497
Middle --> Client : 19310
Client --> Middle : 957
Middle --> Client : 19883
ROUND 3 Client --> Middle : 820
Middle --> Client : 18943
Client --> Middle : 955
Middle --> Client : 19832
ROUND 4 Client --> Middle : 683
Middle --> Client : 18966
Client --> Middle : 953
Middle --> Client : 19690
ROUND 5 Client --> Middle : 371
Middle --> Client : 19080
Client --> Middle : 954
Middle --> Client : 19868
ROUND 6 Client --> Middle : 207
Middle --> Client : 18987
Client --> Middle : 960
Middle --> Client : 19713
AVG Client --> Middle : 569
Middle --> Client : 19051
Client --> Middle : 957
Middle --> Client : 19802
結果表示:
同一個基準點上,WCF的執行效能劣於WEB SERVICE,但若改用netTCPbinding的話,則速度不相上下!
但由於netTCPbinding只適用於.net與.net架構上使用,並不像WEB SERVICE一樣的使用XML進行溝通,因此架構使用上需注意
官方說明:
http://msdn.microsoft.com/zh-tw/library/bb310550%28en-us%29.aspx

2011年2月22日 星期二

[WCF]解決 X64平台上無法開發以Access作為資料庫的應用程式,會發生The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.


問題

X64平台上無法開發以Access作為資料庫的應用程式,會發生The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

最近嘗試著以WCF取代Web Service作為Web服務的平台,卻發生The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.的錯誤訊息 
,且無法解決!!!!!! 

解決方法

原因是在WCF專案屬性設定上並無法將平台由"AnyCPU"變更為"X86"平台,而作為Client端的Windows Form程式卻可以指定平台,因此可能是由於WCF是屬於Hosting的服務,因此系統若是X64則預設只能選X64的平台!

因此嘗試將開發環境由原本的X64作業系統改為在X86的系統上開發,一樣的專案卻可以如期的運行!

2011年2月20日 星期日

[WCF]使用 List<T>傳遞資料( Use List data transfer)


問題

使用 List<T>傳遞資料
WCF上的其中一個Operation定義如下:
1
當在WCF上使用List<T>做為資料交換的參數時,如果Client端沒特別指定時,預設為System.Array
所以即便WCF 服務端定義為List<T>型別的參數,在Client端卻為Array型別
1.1
Client端檢查方式
2
3

解決方法

因此若要將之變更為List<T>的型別,需手動指定
2
4
手動指定後,就可以使用List<T>的方式傳遞參數資料
4.1

2011年1月27日 星期四

[WCF]解決 The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.


問題

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
當Client在呼叫WCF的API時,出現以下的訊息
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

解決方法

打開Client的config檔案,將以下屬性的值加大:
屬性名稱 預設值 可加大範圍
maxBufferSize 655360 655360~2147483647
maxBufferPoolSize 655360 655360~2147483647
maxReceivedMessageSize 655360 655360~2147483647
maxStringContentLength 655360 655360~2147483647
maxArrayLength 655360 655360~2147483647
maxBytesPerRead 655360 655360~2147483647

2011年1月18日 星期二

[WCF]解決 There was no endpoint listening at http://localhost:1104/MyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.


問題

There was no endpoint listening at http://localhost:1104/MyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
當在開發WCF服務的時候,出現此錯誤:
Capture
There was no endpoint listening at http://localhost:1104/MyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

解決方法

看詳細說明:
2
指出問題是無法連到remote server
但由於是處於開發階段,怎會有remote server呢?原因是出在ASP.NET的Development Server尚未啟動,所以處於開發時期的wcf service找不到http://localhost:1104/MyService.svc 這個port為1104的service
解決方式如下:
在MyServices.svc按下右鍵=>選擇使用瀏覽器檢視
Capture3
你就會看到ASP.NET Development Server自動啟動了
Capture4
如果錯誤一樣發生,請檢查一下WCF Service的config所設的<endpoint/>是否位置正確

2011年1月13日 星期四

[WCF]使用 自訂義array的elements(Use custom element of the array)


問題

使用 自訂義array的elements



解決方法

如果想要將回傳的XML elements看起來像這個樣子
<TestCase1>
 <result>1</result>
 <result>0</result>
</TestCase1>
在WCF架構裡該如何實作?
Step1.實作CollectionDataContract如下,注意指定ItemName
[CollectionDataContract(ItemName = "result", Namespace = "http://localhost/TestCase/")]
public class ResultInfo<T> : List<T>
{
    public ResultInfo(): base()
    {
    }
    public ResultInfo(T[] items): base()
    {
        foreach (T item in items)
        {
            Add(item);
        }
    }
}
Step2.宣告使其成為DataMember,讓它可被Client端叫用
[DataMember(IsRequired = false)]
public ResultInfo<string> TestCase1= new ResultInfo<string>();
如此一來,回傳的資料就會如你所要的!!
可以直接這樣用
TestCase1.Add(“1”);
TestCase1.Add(“2”);

熱門文章