gpt4 book ai didi

vb.net - WCF 服务生成的代理类将函数公开为 ByRef Sub

转载 作者:行者123 更新时间:2023-12-04 13:43:00 24 4
gpt4 key购买 nike

我有一个公开单个契约(Contract)和操作的 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 函数)而不是我期望的函数。

更重要的是,生成的 sub 不接受我的消息契约(Contract)作为输入/输出参数,而是列出消息契约(Contract)的成员。

即,我希望自动生成的代理类具有以下签名:
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但是正如您所看到的,我的契约(Contract)中没有涉及枚举 - 枚举的存在导致奇怪的代理类生成被标记为类似帖子中的答案。

是否在任何地方配置代理行为以使用我指定的契约(Contract)?显然我目前处于开发/测试环境中,但是当这最终投入生产时,它将内存和文件流传递给服务,并且返回的流可以是任何格式,老实说,我打算将其视为抽象流类。我现在可以看到的唯一方法是将我的输入流更改为与预期的输出流相同,但肯定有更好的方法吗?

最佳答案

完全的白痴。我没有选中“始终生成消息契约(Contract)”的服务引用配置中的框。

检查后,我的代理类签名已更改为我的 OP 中的预期签名。

为hub-bub道歉^^

关于vb.net - WCF 服务生成的代理类将函数公开为 ByRef Sub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6095617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com