开发者

WCF - CODEGEN: Generating message contract since message FileRequest has headers

I am aware that there is a similar question here with no solution.

I'm working on a WCF streaming service over HTTP.

Here are my MessageContract

[MessageContra开发者_高级运维ct]
public class FileRequest
{
    #region Message Header

    [MessageHeader(MustUnderstand = true)]
    public Credential Credentials { get; set; }

    #endregion

    #region Message body

    [MessageBodyMember(Order = 1)]
    public FileInfo FileInfo { get; set; }

    #endregion

    #region Ctor

    // ...

    #endregion

}

[MessageContract]
public class FileRequestResponse
{
    #region Message Header

    [MessageHeader(MustUnderstand = true)]
    public FileInfo FileHeader { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public OperationResult<bool> OperationResult { get; set; }

    #endregion

    #region Message Body

    [MessageBodyMember]
    public Stream FileStream { get; set; }

    #endregion


    #region Constructor

    // ...

    #endregion

}

Here is my ServiceContract

[ServiceContract(Namespace = "https://service.contract.example.com")]
public interface IUpdateService
{
    [OperationContract(Action = "GetUpdates")]
    OperationResult<List<FileInfo>> GetUpates(ApplicationInfo applicationInfo, Credential credential);

    [OperationContract(Action = "GetFile")]
    FileRequestResponse FileRequest(FileRequest fileRequest);
}

Now the question is why I am getting this error:

// CODEGEN: Generating message contract since message FileRequest has headers

When I add my service reference. The end result is that the service contract wraps the FileRequest operation into a wrapper which I do not want.

public FileInfo FileRequest(Credential Credentials, FileInfo, out OperationResult<bool> OperationResult, out System.IO.Stream FileStream)

NOTE: I have not checked the "Always generate message contracts" in the service reference.


Set [MessageContract(IsWrapped=true)] for all the message contracts in the service and then try generating the proxy .


You might want to try to use the IsWrapped attribute on the message contract:

[MessageContract(IsWrapped=false)]

Not 100% sure which one you'll need (true or false) but that's one of the options you could try.

Also, another observation: I think it's a bit risky to have a method called FileRequest and a message contract which also is called FileRequest.

The generally accepted best practive would be to have a method GetFile, a request message for that called GetFileRequest and a response message type GetFileResponse. Do not use the same names for different things.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜