WCF 代理未正确生成

发布于 2024-12-04 09:13:31 字数 1954 浏览 1 评论 0原文

我有一个 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;
}

我确信我错过了一些简单的东西,但我似乎找不到它是什么。有谁知道可能导致此问题的原因吗?

I have a WCF Service that needs to return a file from a database. To that end, I have created two MessageContract classes, one for input and one for output. The code is as follows:

[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)
{
}

The generated WSDL looks correct:

<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>

However, when I run svcutil.exe http://localhost:8002/IAttachments?wsdl, the generated code comes out as:

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;
}

I'm sure I'm missing something simple, but I can't seem to find what it is. Does anyone have any clues to what could be causing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-12-11 09:13:31

经过进一步检查代码,/messageContract 开关修​​复了其中一个调用,结果却搞砸了另一个调用。但是,使用 /importXmlTypes 开关修复了所有问题。

Upon further examination of the code, the /messageContract switch fixed one of the calls only to screw up another one. However, using the /importXmlTypes switch fixed everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文