Search code examples
c#wcfmessagecontract

A newly added MessageContract doesn't appear in the service reference metadata


I have a MessageContract called Document that looks like this:

[MessageContract]
public class Document : IDisposable
{
    [MessageHeader(MustUnderstand = true)]
    public string FileName;

    [MessageHeader(MustUnderstand = true)]
    public bool IsUploaded = false;

    [MessageBodyMember(Order = 1)]
    public Stream FileByteStream;

    public void Dispose()
    {
        if (FileByteStream != null)
        {
            FileByteStream.Close();
            FileByteStream = null;
        }
    }
}

Which is fine for the most part. It shows up in intellisense and I can instantiate it just fine. But I needed to add a new contract that looks like this:

[MessageContract]
public class Dummy
{
    public int DummyID;
    public Image DummyImage;
    public int PageNumber;
}

Seemed simple enough. I built the project and updated my service reference. But that class doesn't show up and I can't instantiate it.

Any ideas on what I'm doing wrong here?


Solution

  • I got my answer from here.

    Only the types actually used by the service will be reflected in the metadata.

    I didn't have an operation contract that used the DataContract. I didn't need to have one at the time, so I didn't make it. But apparently, unless you have one that uses it, the metadata won't be generated for that DataContract.