0
我有一个WCF服务,需要从数据库中返回一个文件。为此,我创建了两个MessageContract类,一个用于输入,另一个用于输出。代码如下:WCF代理没有正确生成
[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;
}
我当然,我错过了一些简单的东西,但我似乎无法找到它是什么。有没有人有任何线索可能导致这种情况?
如果你用'/ wrapped'参数调用'svcutil'会怎么样?这将防止“展开”参数(就像在你的情况下发生的那样)。另外 - 尝试svcutil上的'/ messageContract'开关告诉它你正在使用一个消息合约 - 有时帮助... –
没有错 - 合同是一样的。你应该可以用这个客户端调用服务,它应该可以很好地工作。 – carlosfigueira
谢谢。/messagecontract开关有窍门。只要我弄清楚,我会接受你的答案。 carlosfigueira:虽然我知道它在技术上是正确的并且可以工作,但现在它是如何编写原始通话并且更糟,这并不直观。我的老板永远不会在我们的代码中接受这样的电话。 –