2010/04/23

WCF 歷險記

WCF Test Client Tool

  • SOA Cleaner
    • 好用,但是不是免費
    • 支援 DataTable / DataSet
    • 不支援 maxBufferPoolSize , maxReceivedMessageSize
  • WCFTestClient.exe (Build in Visual Studio)
    • C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe
    • 不支援 DataTable / DataSet

 

Q:呼叫多次出現 cannot be used for communication because it is in the Faulted state.

A:http://msdn.microsoft.com/en-us/library/aa355056.aspx

Client 避免使用 Using 改用 Try...Catch...

WCF Client Avoiding Problems with the Using Statement

Aa355056.note(en-us,VS.100).gifNote:

The using statement and ServiceHost: Many self-hosting applications do little more than host a service, and ServiceHost.Close rarely throws an exception, so such applications can safely use the using statement with ServiceHost. However, be aware that ServiceHost.Close can throw a CommunicationException, so if your application continues after closing the ServiceHost, you should avoid the using statement and follow the pattern previously given.

=====

Q: WCF Proxy Class can not generated 無法自動產生 Service Reference?

A: 有可能含有 WCF 不支援的型別,例如 DateTime?
可以使用 DataContractAttribute 排除

http://msdn.microsoft.com/zh-tw/library/system.runtime.serialization.datacontractattribute%28VS.90%29.aspx

=====

Q:為什麼回傳 DataTable 會出現錯誤?

A:序列化時 DataTable.TableName 為必填欄位,要記得指定。

=====

Q:為什麼無法回傳 Enum 型別?

A:需設定 [EnumMember] 在 Client 才會出現正確

範例:

[DataContract]
public enum FuncRight { [EnumMember]Read, [EnumMember] Edit };

Sharing Enum with WCF Service

沒有留言: