我有一个WCF服务公开单个合同和操作:
<ServiceContract(Namespace:="ImageSystem")> _
Public Interface IUploadService
<OperationContract()> _
Function UploadFile(ByVal file As ImageUpload) As ImageUpload
End Interface
该函数接收并返回“ImageUpload”,其定义如下:
<MessageContract()> _
Public Class ImageUpload
<MessageHeader()> _
Public Property ImageID() As Nullable(Of Long)
<MessageHeader()> _
Public Property ImageTypeID() As Long
<MessageHeader()> _
Public Property IncludeInGallery() As Boolean
<MessageHeader()> _
Public Property OriginalFileName() As String
<MessageHeader()> _
Public Property ErrorDescription() As String
<MessageBodyMember()> _
Public Data As System.IO.Stream
End Class
端点定义如下(不确定这个问题是否太重要,但以防万一):
客户端:
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpStreamBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Streamed" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="20971520" maxConnections="10" maxReceivedMessageSize="20971520">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:809/UploadService" binding="netTcpBinding"
bindingConfiguration="netTcpStreamBinding" contract="UploadService.Local.IUploadService"
name="NetTcpBinding_IUploadService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
服务器:
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpStreamBinding" transferMode="StreamedRequest" maxBufferSize="20971520"
maxReceivedMessageSize="20971520" >
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="UploadServiceBehaviour"
name="ImageSystem.SVC.UploadService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpStreamBinding"
contract="ImageSystem.SVC.IUploadService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:809/UploadService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="UploadServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the
metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true.
Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我的问题是通过向客户端添加服务引用而生成的代理类正在生成sub(void函数)而不是我期望的函数。
更重要的是,生成的子网不接受我的消息合同作为输入/输出参数,而是列出消息合同的成员。
即,我希望自动生成的代理类具有以下签名:
Public Function UploadFile(ByVal file As ImageUpload) As ImageUpload
相反,它正在产生:
Public Sub UploadFile(ByRef ErrorDescription As String, ByRef ImageID As System.Nullable(Of Long), ByRef ImageTypeID As Long, ByRef IncludeInGallery As Boolean, ByRef OriginalFileName As String, ByRef Data As System.IO.Stream)
Dim inValue As UploadService.Local.ImageUpload = New UploadService.Local.ImageUpload()
inValue.ErrorDescription = ErrorDescription
inValue.ImageID = ImageID
inValue.ImageTypeID = ImageTypeID
inValue.IncludeInGallery = IncludeInGallery
inValue.OriginalFileName = OriginalFileName
inValue.Data = Data
Dim retVal As UploadService.Local.ImageUpload = CType(Me,UploadService.Local.IUploadService).UploadFile(inValue)
ErrorDescription = retVal.ErrorDescription
ImageID = retVal.ImageID
ImageTypeID = retVal.ImageTypeID
IncludeInGallery = retVal.IncludeInGallery
OriginalFileName = retVal.OriginalFileName
Data = retVal.Data
End Sub
这随后会导致流式转换问题,因为生成的函数允许我将内存流作为输入传递(在传递给服务时可以正常工作),而不是传回给我一个新的响应流,它试图将从服务接收的MessageBodyStream转换为我的内存流。
这在某些方面类似于other posts,但正如您所看到的,我的合同中没有涉及枚举 - Enums的存在导致奇怪的代理类生成被标记为类似帖子中的答案。 / p>
我是否在任何地方配置代理行为以使用我指定的合同?显然我当前在开发/测试环境中,但是当它最终投入生产时,它将是传递给服务的内存和文件流,并且返回的流可以是任何格式,说实话,我打算将其视为抽象流类。我现在能看到的唯一解决方法是将 in 流更改为与预期的 out 流相同,但肯定有更好的方法吗?
答案 0 :(得分:3)
总白痴。我没有在“始终生成消息合同”的服务参考配置中选中该框。
检查后,我的代理类签名已更改为我的OP中的预期签名。
为hub-bub道歉^^