开发者

Reference type is changed in proxy class that generated from WCF

开发者 https://www.devze.com 2023-04-01 08:22 出处:网络
I know the title is little confusing, so here is the explaination: I am trying to streaming a large file with WCF and I kind of know how to do it.

I know the title is little confusing, so here is the explaination:

I am trying to streaming a large file with WCF and I kind of know how to do it.

When I wrote a method say:

    [OperationContract]
    void sendStream(System.IO.Stream _StreamSource);

There, the generated proxy class insides my Client App will have the System.IO.Stream type as input parameter correctly.

But if I create another class:

[MessageContract]
[KnownType(typeof(Stream))]
public class MyData
{
    [MessageHeader(MustUnderstand = true)]
    public string Key { get; set; }
    [MessageBodyMember(Order = 1)]
    public Stream Data { get; set; }
}

And have the ser开发者_JAVA技巧vice interface:

    [OperationContract]
    void sendStream(MyData _StreamSource);

The stream type from MyData in my client class will be under Service Reference namespace.

i.e: MyServiceRef.Stream

Which made me cannot pass the stream to WCF.

But this doesn't happen for string and int stuff.

I wonder why, I throught Stream type is known type like string and int?

Or is there any workaround?

Thanks in advance!


The KnownType attribute instructs WCF to add type definitions to the service reference. It appears that this also has the side effect of making any properties of a KnownType inside the DataContract to use the service-generated type. (This makes sense for the normal usage of KnownType, where WCF does not otherwise know about the type.)

Did you try using the contract without declaring Stream as a KnownType?


Stream is not serializable like int or string. So you can't use them as a property of a messagecontract.

You can, however, use streaming in wcf : http://msdn.microsoft.com/en-us/library/ms731913.aspx, but this require to have the stream as the unique parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号