我有一个 wcf 服务,它是异步的并使用 net tcp 绑定。到目前为止,它工作正常。我可以获取元数据,为客户端生成代理类......等等。
但是,我需要定义一个消息契约,因为我需要从客户端向服务发送文件。这个类在一个公共库中,我也有 STE(自我跟踪实体)。
我还在服务中添加了新的异步方法,让我可以发送文件。
我的消息合同如下:
[MessageContract]
public class FileDataStream : IDisposable
{
//[MessageHeader(MustUnderstand = true)]
public string Name {get; set;}
//[MessageBodyMember(Order = 1)]
public System.IO.Stream DataStream {get; set;}
}
如果我使用这个类,当我尝试以与过去相同的方式获取元数据时,现在在 Internet Explorer 中说我找不到该页面。客户端无法连接。如果我使用 netstat -ona | 找到“7997”我什么也没得到,所以服务没有正常运行。
但是,如果在我的消息合同类中我删除了 messagecontract 属性,则一切正常。我的意思是一切正常是因为服务运行正常。
但是,文件的二进制信息无法正确到达服务。在我阅读的有关在 WCF 中传输文件的示例中,我总是看到使用消息协定,因为要发送更多信息,例如文件名,需要消息协定。
所以我想知道我做错了什么。在其他情况下,当我无法获取元数据时,是因为我没有正确设置绑定,但是我不知道在我想使用消息合约时是否需要特殊配置。
我的服务配置如下:
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="ServiceDocumentos" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"
transferMode="Streamed" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:20:00"
sendTimeout="00:01:00" maxConnections="100">
<security mode="None"/>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxStringContentLength="2147483647"/>
</binding>
<binding name="ServiceCore" maxBufferSize="67108864"
maxReceivedMessageSize="67108864" maxBufferPoolSize="67108864"
transferMode="Buffered" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:20:00"
sendTimeout="00:01:00" maxConnections="100">
<security mode="None"/>
<readerQuotas maxArrayLength="67108864" maxBytesPerRead="67108864" maxStringContentLength="67108864"/>
<reliableSession enabled="true" inactivityTimeout="00:20:00" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="CMMSService" name="GTS.CMMS.Service.Service">
<endpoint binding="netTcpBinding" bindingConfiguration="ServiceDocumentos"
name="ServiceDocumentos" contract="GTS.CMMS.Service.IServiceDocumentos"
address="ServiceDocumentos/">
</endpoint>
<endpoint address ="ServiceCore/"
binding="netTcpBinding" bindingConfiguration="ServiceCore"
name="ServiceCore" contract="GTS.CMMS.Service.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
listenUriMode="Explicit">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:7997/CMMSService" />
<add baseAddress="net.tcp://localhost:7998/CMMSService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CMMSService">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceThrottling
maxConcurrentCalls="64"
maxConcurrentInstances="2147483647"
maxConcurrentSessions="50"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
谢谢。