1

我有一个错误:

Type 'MyAppApp.Web.MyAppWebService.NotifierAuthHeader' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute. Consider marking the base type 'System.Web.Services.Protocols.SoapHeader' with DataContractAttribute or SerializableAttribute, or removing them from the derived type.

执行此 wcf 方法时:

<OperationContract()> <WebMethod(Description:="Gets details about selected PDF document")> _
    Public Function GetPdfDetails(ByVal pdfName As String) As String

我无法更改 SoapHeader,因为它是框架类

Public MustInherit Class SoapHeader
          Inherits System.Object
     Member of System.Web.Services.Protocols

我在课堂上使用这个 NotifierAuthHeader

Imports System.Web.Services.Protocols
Imports System.Runtime.Serialization 

Public Class NotifierAuthHeader
    Inherits SoapHeader

    Public HandlerId As Integer
    Public Guid As Byte()
End Class

我有点困惑。我怎样才能让它工作?

4

2 回答 2

1

我认为您需要将 WebMethod 与 OperationContract 分开。

如果目标是对 Web 服务和 WCF 服务使用相同的方法,那么您需要将该方法的副本移动到单独的 asmx 中。

于 2011-12-15T16:37:12.177 回答
1

您是否故意尝试混合两种技术?SoapHeader来自传统的 ASMX 技术,但OperationContract来自 WCF。

要在 WCF 中使用标头,您需要使用消息协定,它可以包含标头部分和正文部分。

于 2011-12-15T16:53:31.097 回答