Basic WCF question
I usually can create an instance of a class called SalesItem
and pass that as a parameter to a web service like so webService.CreateSalesitem(New SalesItem())
This works fine.
I then subclassed my SalesItem
class. I called it GP_Item_SIM_Product
. However when I try to pass this class as a paramter to my web service, I get an exception. webService.CreateSalesitem(new GP_Item_SIM_Product()
)
Here is the exception:
There was an error while trying to serialize parameter http://schemas.microsoft.com/dynamics/gp/2010/01:salesItem. The InnerException message was 'Type 'IMS.GP_Item_SIM_Product' with data contract name 'GP_Item_SIM_Product:http://schemas.datacontract.org/2004/07/IMS' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
Here is my subclass:
Imports System.ServiceModel
Imports GP_1.DynamicsGPClient
Imports GP_1.Microsoft.Dynamics.GP
Imports GP_1.Microsoft.Dynamics.Common
Imports SierraLib
Imports GP_1.GP
Imports GP_1
Imports System.Runtime.Serialization
< DataContract() > _
Public Cla开发者_如何学Css GP_Item_SIM_Product
Inherits SalesItem
Dim SIMProduct As Products
Dim greatPlainsRunner As GPRunner
Public Sub New(ByVal gpr As GPRunner, ByVal product As Products)
SIMProduct = product
greatPlainsRunner = gpr
SetValues()
End Sub
Private Sub SetValues()
Me.Key = New ItemKey() With {.Id = SIMProduct.MFGPN}
Me.Description = Description
Me.CurrentCost = New MoneyAmount() With {.Currency = Defaults.usCurrency, .Value = CDec(SIMProduct.Cost)}
Me.StandardCost = New MoneyAmount() With {.Currency = Defaults.usCurrency, .Value = CDec(SIMProduct.Price)}
Me.IsDiscontinued = Not SIMProduct.Enabled
Me.SalesTaxBasis = IIf(CBool(SIMProduct.Taxed = True),
GP_1.Microsoft.Dynamics.GP.SalesTaxBasis.Taxable,
GP_1.Microsoft.Dynamics.GP.SalesTaxBasis.Nontaxable)
End Sub
End Class
Any ideas how I can modify my class so that it can be sent to the web service. I think it has something to do with the two fields in this class that I added. Not sure if I need to mark them as anything special.
Try adding <ServiceKnownType(GetType(GP_Item_SIM_Product))>
to your service contract.
You need to add the ServiceKnownType
attribute to the service contract - that's the Interface
that defines your serivce and contains the signature for the CreateSalesitem
operation.
<ServiceKnownType(GetType(GP_Item_SIM_Product))>
Public Interface IWebService
精彩评论