我在基于ajax的WCF服务上遇到上述错误。代码如下所示。
<ServiceContract()>
Public Interface IEditInitiatives
<OperationContract()> _
<WebInvoke(BodyStyle:=WebMessageBodyStyle.WrappedRequest, ResponseFormat:=WebMessageFormat.Json, UriTemplate:="GetGridData")> _
Function GetGridData(session As String) As List(Of InitiativeData)
<OperationContract()> _
<WebInvoke(Method:="POST", BodyStyle:=WebMessageBodyStyle.WrappedRequest, ResponseFormat:=WebMessageFormat.Json)> _
Function SaveGridData(input As String) As String
End Interface
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class EditInitiatives
Implements IEditInitiatives
Function GetGridData(session As String) As List(Of InitiativeData) Implements IEditInitiatives.GetGridData
'Business logice
End Function
Function SaveGridData(ByVal input As String) As String Implements IEditInitiatives.SaveGridData
Return "ok"
End Function
End Class
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyCompany.CostReduction.EditInitiativesAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MyCompany.CostReduction.EditInitiatives" behaviorConfiguration="metadataBehavior">
<endpoint address="" behaviorConfiguration="MyCompany.CostReduction.EditInitiativesAspNetAjaxBehavior" binding="webHttpBinding" contract="MyCompany.CostReduction.IEditInitiatives" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="UsernameWithTransport">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
答案 0 :(得分:0)
捅了一下:
[Serializable]
[DataContract]
确保将这些属性放在InitiativeData
上using System.Collections.ObjectModel;
using System.Runtime.Serialization;