WCF 代理未正确生成
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过进一步检查代码,
/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.