【发布时间】:2011-05-24 05:58:17
【问题描述】:
我正在尝试将 MessageContract 添加到我的 WCF 服务中,类似于这个问题中发生的事情:WCF: using streaming with Message Contracts
这是我得到的例外: 无法加载操作“UploadFile”,因为它具有 System.ServiceModel.Channels.Message 类型的参数或返回类型,或者具有 MessageContractAttribute 和其他不同类型参数的类型。使用 System.ServiceModel.Channels.Message 或带有 MessageContractAttribute 的类型时,该方法不得使用任何其他类型的参数。
这是我的合同:
[ServiceContract]
public interface IFile
{
[OperationContract]
bool UploadFile(FileUpload upload);
}
[MessageContract]
public class FileUpload
{
[MessageHeader(MustUnderstand = true)]
public int Username { get; set; }
[MessageHeader(MustUnderstand = true)]
public string Filename { get; set; }
[MessageBodyMember(Order = 1)]
public Stream ByteStream { get; set; }
}
这是我在 app.config 中使用的绑定配置:
<netTcpBinding>
<binding name="TCPConfiguration" maxReceivedMessageSize="67108864" transferMode="Streamed">
<security mode="None" />
</binding>
</netTcpBinding>
现在我在想这可能与我使用的绑定类型有关,但我不完全确定。
【问题讨论】:
-
如果你在创建服务宿主实例之前在你的windows服务宿主项目中添加
Debugger.Launch();这行,那么你可以调试你的实例的启动问题,并且能够看到异常是什么。配置文件的更多细节也会很有用。 -
@Sam:感谢您的提示。这条线以后对我来说将非常有用。无论如何,这是我从中得到的异常消息:无法加载操作“UploadFile”,因为它具有 System.ServiceModel.Channels.Message 类型的参数或返回类型或具有 MessageContractAttribute 和其他参数的类型不同种类。使用 System.ServiceModel.Channels.Message 或带有 MessageContractAttribute 的类型时,该方法不得使用任何其他类型的参数。
标签: c# wcf messagecontract wcf-streaming