开发者

WCF MessageContract formatting issue

I have a problem of WCF definition of MessageContact and client calling function.

Scenario; Client called the service with a string type reference ID and server responds instance of type of AudioObject. AudioObject consists of Stream as MessageBodyMember and FormatObject as a MessageHeader.

Following is WCF code snippet.

[ServiceContract]
public interface IAudioStreamService
{
    [OperationContract]
    AudioObject GetAudioDataStream(StringMessage RefID);
}

//StringMessageContract
[MessageContract]
public class StringMessage
{
    [MessageBodyMember]
    public string Name;
}

[MessageContract]
public class AudioObject
{
    Stream _audioStream;
    AudioFormat _audioFormat;

    [MessageBodyMember (Order=1)]
    public Stream AudioStream
    {
        get { return _a开发者_如何学GoudioStream; }
        set { _audioStream = value; }
    }

    [MessageHeader(MustUnderstand=true)]
    public AudioFormat AudioFormat
    {
        get { return _audioFormat; }
        set { _audioFormat = value; }
    }
}

[DataContract]
public class AudioFormat
{
    int _nChannels;
    int _nKilloBitsPerSec;
    int _nSamplesPerSec;

    [DataMember(Name="nChannels", Order=0, IsRequired=true)]
    public int nChannels
    {
        get { return _nChannels; }
        set { _nChannels = value; }
    }
    [DataMember(Name = "nKilloBitsPerSec", Order = 1, IsRequired = true)]
    public int nKilloBitsPerSec
    {
        get { return _nKilloBitsPerSec; }
        set { _nKilloBitsPerSec = value; }
    }
    [DataMember(Name = "nSamplesPerSec", Order = 2, IsRequired = true)]
    public int nSamplesPerSec
    {
        get { return _nSamplesPerSec; }
        set { _nSamplesPerSec = value; }
    }
}

The client side code is as follows,

BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = 176160768;                       
EndpointAddress endpointAddress = new EndpointAddress("URLToService");
AudioStreamServiceClient client = new AudioStreamServiceClient(binding, 
endpointAddress);
    AudioFormat audioFormat = client.GetAudioDataStream("000", out serverStream); 

The above code is worked fine. But the issue is,

In order to the format of the OperationContract, I expected the client code as follows,

AudioObject audioObject = client.GetAudioDataStream("0000");

But my ServiceReference generated the client-stub other way round(as shown in code). Can anybody explain me the reason for this matter.


Either write a client yourself by deriving a class from ClientBase or write an extension method with the method signature of your choice.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜