WCF代理未正确生成

时间:2011-09-14 20:18:07

标签: wcf wsdl svcutil.exe

我有一个需要从数据库返回文件的WCF服务。为此,我创建了两个MessageContract类,一个用于输入,另一个用于输出。代码如下:

[MessageContract]
public class AttachmentFile
{
    [MessageHeader(MustUnderstand = true)]
    public Int32 AttachmentID;

    [MessageHeader]
    public String FileName;

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

    public AttachmentFile(Attachment att)
    {
        AttachmentID = (Int32)att.AttachmentID;
        FileName = att.FileName;
        Data = new MemoryStream(att.FileBytes);
    }
}

[MessageContract]
public class AttachmentFileID
{
    [MessageBodyMember]
    public Int32 AttachmentID;
}

public AttachmentFile GetAttachmentFile(AttachmentFileID AttachmentID)
{
}

生成的WSDL看起来是正确的:

<wsdl:operation name="GetAttachmentFile">
    <soap12:operation soapAction="http://tempuri.org/IAttachments/GetAttachmentFile" style="document"/>
    <wsdl:input name="AttachmentFileID">
        <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output name="AttachmentFile">
        <soap12:header message="i0:AttachmentFile_Headers" part="AttachmentID" use="literal"/>
        <soap12:header message="i0:AttachmentFile_Headers" part="FileName" use="literal"/>
        <soap12:body use="literal"/>
    </wsdl:output>
</wsdl:operation>

但是,当我运行svcutil.exe http://localhost:8002/IAttachments?wsdl时,生成的代码如下:

public string GetAttachmentFile(ref int AttachmentID, out System.IO.Stream Data)
{
    AttachmentFileID inValue = new AttachmentFileID();
    inValue.AttachmentID = AttachmentID;
    AttachmentFile retVal = ((IAttachments)(this)).GetAttachmentFile(inValue);
    AttachmentID = retVal.AttachmentID;
    Data = retVal.Data;
    return retVal.FileName;
}

我确定我错过了一些简单的东西,但我似乎无法找到它是什么。有没有人有任何可能导致这种情况的线索?

1 个答案:

答案 0 :(得分:1)

在进一步检查代码后,/messageContract开关修复了其中一个调用,只是为了搞定另一个调用。但是,使用/ importXmlTypes开关修复了所有内容。