R.Tanaka.Ichiro's Blog

主にC# な話題です

目次

Blog 利用状況

ニュース

WCF の DataContract 属性のついたクラスの汎用性(その2)

WCF の DataContract 属性のついたクラスの汎用性
http://blogs.wankuma.com/rti/archive/2008/08/19/153479.aspx

の続きです。


「前回までのあらすじ」

アセンブリA(WcfServiceLibrary)
・アセンブリCを参照
・DataConstract 属性が付いたHogeClassを保有

アセンブリB(WcfClient)
・アセンブリCを参照
・アセンブリAをサービス参照することで HogeClass を利用

アセンブリC(Common Logic Library)
・ここでアセンブリAにあるHogeClass型を使いたい
・アセンブリCはアセンブリA,B から参照される

簡単に言うと、

DataConstract なオブジェクトを使いまわすには!?

ってことです。


その後、試してみた結果、どうやら インターフェイスなら DataContract 属性付きのクラスが継承できることがわかりました。

つまり、インターフェイスに格納した状態であれば DataContract 属性付きのオブジェクトを各アセンブリで使いまわして処理することができます。

こんな感じです。


namespace CommonLogicLibrary
{
  public interface IRow
  {
    int Code { get; set; }
    string Name { get; set; }
    int Age { get; set; }
  }
  public class Row
  {
    public IRow Row { get; set; }
    pubilc void ChangeAge() {
      this.Row.Age = 18;
    }
  }
}

namespace WcfServiceLibrary
{
  [DataContract]
  public class Row : CommonLogicLibrary.IRow
  {
    [DataMember] public int  Code { get; set; }
    [DataMember] public string Name { get; set; }
    [DataMember] public int  Age  { get; set; }
  }
}


これによって、 インスタンスの生成については、WcfServiceLibrary か、サービス参照した WcfClient 側で行って、共通した処理は、CommonLogicLibrary の Row オブジェクトに行わせることができます。

 

投稿日時 : 2008年8月27日 13:17

Feedback

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/08/27 14:37 NAL-6295

私もインタフェースを利用する事で事なきを得てます。

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/08/27 15:16 ghost_shell

あ・・・、書いたことある。
それが知りたかったのか・・・。

#RさんはWCFをすんなり使えますか?

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/08/27 20:14 まどか

> アセンブリC(Common Logic Library)
> ・ここでアセンブリAにあるHogeClass型を使いたい
> ・アセンブリCはアセンブリA,B から参照される

これって循環参照ですよね。

前回もちょっと理解できなかったのですが
単純にWCFに関するサービスとクライアントで共有するものを
単独アセンブリに押し込めればいいだけのような気がしてなりません。
とんちんかんなこと言ってるかなぁ?

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/08/28 11:28 R・田中一郎

NAL-6295 さん

>私もインタフェースを利用する事で事なきを得てます。

僕も、最初にインターフェイスを試してみるべきでした。
インターフェイスに対してコーディングするという原則を忘れていた証拠ですね。

DataContract属性付きクラスの継承に対応して欲しいです。
(できる方法があるのかなぁ)

----------------------------------------
ghost_shell さん

>#RさんはWCFをすんなり使えますか?

この問題以外は、今のところ特に不満はないですね。

----------------------------------------
まどか さん

>単純にWCFに関するサービスとクライアントで共有するものを
>単独アセンブリに押し込めればいいだけのような気がしてなりません。

この方法がわからないのですよ。
どうすれば良いのか教えていただきたいです。

DataContract属性付きのクラスを CommonLogic アセンブリにおいて、これを WcfServiceLibrary から継承することまでは可能です。
しかし、クライアント側で指定した値が正しく渡らないんですよね。

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/08/28 13:06 NAL-6295

私の場合は、明示的には項目を持たないステータスくらいしかメンバのないインタフェースだけ用意して、ライブラリにインタフェースを実装したクラスと、テーブル情報だけ渡して、ライブラリ内で、実装したクラスに存在するプロパティを動的に解釈するようにしています。
そうすると、ライブラリ側は明示的な情報を知らなくても良いので都合が良かったんです。

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/08/28 22:00 まどか

前回、なちゃさんが書かれていますが
自動生成したクライアントコードのうち、型宣言をすべてコメントアウトして
インターフェースとクライアントクラスだけを有効にします。
要は型をCommonのものを参照するようにします。
これで型の不一致エラーが無くなるはずだと思います。

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/08/30 17:00 R・田中一郎

NAL-6295 さん

なるほど、ステータスで値の種別を把握して解釈させる訳ですね。
皆さん、この辺はいろいろやり繰りしているんですね。

----------------------------------------
まどか さん

いま一つわからないので教えていただきたいです。

>前回、なちゃさんが書かれていますが

は、

>プロキシを自動生成させなきゃ大丈夫です。

の部分で、これが

>自動生成したクライアントコードのうち、型宣言をすべてコメントアウトして

ってことであってます?
また、これはサービス参照時に作成された Reference.cs の Row 宣言全てをコメントアウトするということを指しますか?

>要は型をCommonのものを参照するようにします。

つまり、Commonライブラリのクラスを、Wcf クライアントアセンブリで利用するということですか?
この場合、シリアライズに関する部分も全て自分で行う必要があるということですよね?

うーむ。

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/09/04 20:59 まどか

> Commonライブラリのクラスを、Wcf クライアントアセンブリで利用するということですか?

はい。
サービスとクライアントの双方から参照する共有ライブラリとします。
#双方に共通する情報のみのアセンブリ

> シリアライズに関する部分も全て自分で行う必要があるということですよね?

独自のものがあればそうだと思いますが
私の実績ではコメントアウト+型既定のシリアライザで動作しています。
#Nonコーディング

別の話ですが
Private _Text As String
Public Property Text As String
において
DataMemberをプロパティ側につけると""をNothingで受け取ってしまうという現象がありました。
フィールドにつけると正しく受け取れました。

# re: WCF の DataContract 属性のついたクラスの汎用性(その2) 2008/09/09 9:59 R・田中一郎

なるほど、とりあえずミニマムなソリューション作って検証してみることにします。
ありがとうございました。

#また聞いてしまうかもですが^^;

# always i used to read smaller articles that as well clear their motive, and that is also happening with this piece of writing which I am reading at this place. 2019/05/04 21:57 always i used to read smaller articles that as we

always i used to read smaller articles that as well clear their motive, and that is also happening with this piece of writing which I am
reading at this place.

# I'm not sure where you are getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for great information I was looking for this info for my mission. 2019/05/12 2:09 I'm not sure where you are getting your info, but

I'm not sure where you are getting your info, but good topic.
I needs to spend some time learning more or understanding more.
Thanks for great information I was looking
for this info for my mission.

# Hello! I could have sworn I've been to this website before but after browsing through many of the articles I realized it's new to me. Anyways, I'm definitely happy I found it and I'll be book-marking it and checking back often! 2019/05/15 19:24 Hello! I could have sworn I've been to this websit

Hello! I could have sworn I've been to this website before but after browsing through many of the articles
I realized it's new to me. Anyways, I'm definitely happy I found it and
I'll be book-marking it and checking back often!

# I know this web site provides quality dependent posts and other material, is there any other site which gives these kinds of stuff in quality? 2019/07/25 18:28 I know this web site provides quality dependent po

I know this web site provides quality dependent
posts and other material, is there any other site which gives these kinds of stuff in quality?

# I know this web site provides quality dependent posts and other material, is there any other site which gives these kinds of stuff in quality? 2019/07/25 18:29 I know this web site provides quality dependent po

I know this web site provides quality dependent
posts and other material, is there any other site which gives these kinds of stuff in quality?

# I know this web site provides quality dependent posts and other material, is there any other site which gives these kinds of stuff in quality? 2019/07/25 18:30 I know this web site provides quality dependent po

I know this web site provides quality dependent
posts and other material, is there any other site which gives these kinds of stuff in quality?

# I know this web site provides quality dependent posts and other material, is there any other site which gives these kinds of stuff in quality? 2019/07/25 18:31 I know this web site provides quality dependent po

I know this web site provides quality dependent
posts and other material, is there any other site which gives these kinds of stuff in quality?

# My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using Movable-type on a variety of websites for about a year and am nervous about switching t 2019/07/31 20:22 My programmer is trying to convince me to move to

My programmer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the costs.

But he's tryiong none the less. I've been using Movable-type on a variety of websites
for about a year and am nervous about switching to another platform.
I have heard good things about blogengine.net.
Is there a way I can transfer all my wordpress posts into it?
Any help would be really appreciated!

# My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using Movable-type on a variety of websites for about a year and am nervous about switching t 2019/07/31 20:23 My programmer is trying to convince me to move to

My programmer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the costs.

But he's tryiong none the less. I've been using Movable-type on a variety of websites
for about a year and am nervous about switching to another platform.
I have heard good things about blogengine.net.
Is there a way I can transfer all my wordpress posts into it?
Any help would be really appreciated!

# My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using Movable-type on a variety of websites for about a year and am nervous about switching t 2019/07/31 20:24 My programmer is trying to convince me to move to

My programmer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the costs.

But he's tryiong none the less. I've been using Movable-type on a variety of websites
for about a year and am nervous about switching to another platform.
I have heard good things about blogengine.net.
Is there a way I can transfer all my wordpress posts into it?
Any help would be really appreciated!

# My programmer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using Movable-type on a variety of websites for about a year and am nervous about switching t 2019/07/31 20:25 My programmer is trying to convince me to move to

My programmer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the costs.

But he's tryiong none the less. I've been using Movable-type on a variety of websites
for about a year and am nervous about switching to another platform.
I have heard good things about blogengine.net.
Is there a way I can transfer all my wordpress posts into it?
Any help would be really appreciated!

# HATpJwrKQVNNrjIvM 2021/07/03 1:48 https://unsplash.com/@elizacastaneda

You have made some really good points there. I looked on the net for more info about the issue and found most individuals will go along with your views on this website.

# RHqErqRTiTYwUWRjjzg 2021/07/03 4:48 https://www.blogger.com/profile/060647091882378654

Very informative blog.Really looking forward to read more. Great.

# Excellent items from you, man. I've keep in mind your stuff previous to and you're simply too magnificent. I really like what you've acquired here, certainly like what you are stating and the way through which you assert it. You are making it enjoyable 2021/09/05 6:05 Excellent items from you, man. I've keep in mind y

Excellent items from you, man. I've keep in mind your
stuff previous to and you're simply too magnificent.
I really like what you've acquired here, certainly like what
you are stating and the way through which you assert it.

You are making it enjoyable and you continue to take care of to stay it wise.
I cant wait to learn much more from you. This is
really a terrific site.

# Hello mates, good article and fastidious urging commented at this place, I am genuinely enjoying by these. https://parttimejobshiredin30minutes.wildapricot.org/ part time jobs hired in 30 minutes 2021/10/23 0:34 Hello mates, good article and fastidious urging c

Hello mates, good article and fastidious urging
commented at this place, I am genuinely enjoying by these.
https://parttimejobshiredin30minutes.wildapricot.org/ part time jobs hired in 30 minutes

# Hi! I know this is sort of off-topic but I had to ask. Does operating a well-established website like yours take a large amount of work? I am completely new to blogging but I do write in my diary on a daily basis. I'd like to start a blog so I can share 2021/10/25 22:53 Hi! I know this is sort of off-topic but I had to

Hi! I know this is sort of off-topic but I had to ask. Does
operating a well-established website like yours take a large amount of work?

I am completely new to blogging but I do write in my diary on a daily basis.

I'd like to start a blog so I can share my experience and feelings online.
Please let me know if you have any kind of suggestions or tips
for new aspiring blog owners. Appreciate it!

# Hi! I know this is kinda off topic but I was wondering if you knew where I could locate a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having trouble finding one? Thanks a lot! 2022/03/23 1:17 Hi! I know this is kinda off topic but I was wonde

Hi! I know this is kinda off topic but I was wondering if you knew where
I could locate a captcha plugin for my comment form?
I'm using the same blog platform as yours and I'm having trouble finding one?
Thanks a lot!

# I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space . Exploring in Yahoo I at last stumbled upon this site. Studying this info So i am happy to convey that I have a very just right uncanny feeling I 2022/03/24 6:55 I've been exploring for a little bit for any high-

I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space
. Exploring in Yahoo I at last stumbled upon this site.
Studying this info So i am happy to convey that I have a very just
right uncanny feeling I found out exactly what I needed.
I so much undoubtedly will make certain to do not put out of your mind this site and provides it a glance on a continuing
basis.

# I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space . Exploring in Yahoo I at last stumbled upon this site. Studying this info So i am happy to convey that I have a very just right uncanny feeling I 2022/03/24 6:56 I've been exploring for a little bit for any high-

I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space
. Exploring in Yahoo I at last stumbled upon this site.
Studying this info So i am happy to convey that I have a very just
right uncanny feeling I found out exactly what I needed.
I so much undoubtedly will make certain to do not put out of your mind this site and provides it a glance on a continuing
basis.

# I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space . Exploring in Yahoo I at last stumbled upon this site. Studying this info So i am happy to convey that I have a very just right uncanny feeling I 2022/03/24 6:57 I've been exploring for a little bit for any high-

I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space
. Exploring in Yahoo I at last stumbled upon this site.
Studying this info So i am happy to convey that I have a very just
right uncanny feeling I found out exactly what I needed.
I so much undoubtedly will make certain to do not put out of your mind this site and provides it a glance on a continuing
basis.

# I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space . Exploring in Yahoo I at last stumbled upon this site. Studying this info So i am happy to convey that I have a very just right uncanny feeling I 2022/03/24 6:58 I've been exploring for a little bit for any high-

I've been exploring for a little bit for any high-quality articles or weblog posts on this kind of space
. Exploring in Yahoo I at last stumbled upon this site.
Studying this info So i am happy to convey that I have a very just
right uncanny feeling I found out exactly what I needed.
I so much undoubtedly will make certain to do not put out of your mind this site and provides it a glance on a continuing
basis.

# If you are going for finest contents like me, just pay a visit this website daily as it offers quality contents, thanks 2022/03/24 17:09 If you are going for finest contents like me, just

If you are going for finest contents like me, just pay a visit this website daily as it offers quality contents,
thanks

# If you are going for finest contents like me, just pay a visit this website daily as it offers quality contents, thanks 2022/03/24 17:10 If you are going for finest contents like me, just

If you are going for finest contents like me, just pay a visit this website daily as it offers quality contents,
thanks

# Spot on with this write-up, I truly think this site needs far more attention. I'll probably be back again to read through more, thanks for the advice! 2022/03/25 3:39 Spot on with this write-up, I truly think this sit

Spot on with this write-up, I truly think this site needs far more attention. I'll probably be back again to read through more, thanks for the advice!

# I do not even know the way I ended up here, however I assumed this post used to be great. I do not know who you are however definitely you are going to a famous blogger for those who aren't already. Cheers! 2022/06/05 10:20 I do not even know the way I ended up here, howeve

I do not even know the way I ended up here, however I assumed this post used to be great.

I do not know who you are however definitely you are going to a famous blogger for those who
aren't already. Cheers!

# I'm not certain where you are getting your information, but good topic. I needs to spend some time finding out more or working out more. Thanks for magnificent information I was on the lookout for this information for my mission. 2022/06/06 14:52 I'm not certain where you are getting your informa

I'm not certain where you are getting your information, but good
topic. I needs to spend some time finding out more or working out more.
Thanks for magnificent information I was on the lookout
for this information for my mission.

# Hi there, I enjoy reading through your article post. I like to write a little comment to support you. 2022/06/09 10:33 Hi there, I enjoy reading through your article pos

Hi there, I enjoy reading through your article post. I like to write a little comment to support you.

# I'm gone to tell my little brother, that he should also pay a visit this weblog on regular basis to get updated from newest information. 2022/06/11 14:03 I'm gone to tell my little brother, that he should

I'm gone to tell my little brother, that he should also pay a visit this weblog on regular basis to get
updated from newest information.

# I think this is one of the most vital information for me. And i'm glad reading your article. But should remark on some general things, The website style is perfect, the articles is really great : D. Good job, cheers 2022/06/13 4:21 I think this is one of the most vital information

I think this is one of the most vital information for me. And i'm glad reading your
article. But should remark on some general things, The website style is perfect,
the articles is really great : D. Good job, cheers

# I was wondering if you ever considered changing the page layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot 2022/07/23 7:46 I was wondering if you ever considered changing th

I was wondering if you ever considered changing the page layout of your website?
Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect with it better.

Youve got an awful lot of text for only having 1 or
two images. Maybe you could space it out better?

# I was wondering if you ever considered changing the page layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot 2022/07/23 7:46 I was wondering if you ever considered changing th

I was wondering if you ever considered changing the page layout of your website?
Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect with it better.

Youve got an awful lot of text for only having 1 or
two images. Maybe you could space it out better?

# Link exchange is nothing else except it is simply placing the other person's blog link on your page at suitable place and other person will also do same in support of you. 2022/07/26 18:53 Link exchange is nothing else except it is simply

Link exchange is nothing else except it is simply placing the other person's blog link on your page at suitable place and other
person will also do same in support of you.

# Hi there, I found your web site by way of Google at the same time as looking for a comparable subject, your website came up, it looks great. I've bookmarked it in my google bookmarks. Hi there, simply was aware of your weblog thru Google, and located t 2022/08/04 0:18 Hi there, I found your web site by way of Google a

Hi there, I found your web site by way of Google at the same
time as looking for a comparable subject, your website came up, it looks great.
I've bookmarked it in my google bookmarks.
Hi there, simply was aware of your weblog thru Google,
and located that it's really informative.

I am going to be careful for brussels. I'll be grateful if
you proceed this in future. Lots of folks can be benefited from your writing.
Cheers!

# you are in point of fact a good webmaster. The site loading velocity is incredible. It sort of feels that you're doing any unique trick. Also, The contents are masterpiece. you have done a great task in this subject! 2022/08/07 21:48 you are in point of fact a good webmaster. The sit

you are in point of fact a good webmaster. The site loading velocity is incredible.
It sort of feels that you're doing any unique trick.
Also, The contents are masterpiece. you have done a great task in this subject!

# This is a topic which is near to my heart... Best wishes! Exactly where are your contact details though? 2022/08/08 17:20 This is a topic which is near to my heart... Best

This is a topic which is near to my heart... Best wishes! Exactly where are your contact details though?

# This is a topic that's close to my heart... Best wishes! Exactly where are your contact details though? 2022/08/20 1:26 This is a topic that's close to my heart... Best w

This is a topic that's close to my heart...
Best wishes! Exactly where are your contact
details though?

タイトル  
名前  
Url
コメント