合同名称' MyCompany.CostReduction.EditInitiatives'无法在合同列表中找到服务' EditInitiatives'

时间:2013-05-15 16:51:09

标签: asp.net ajax json wcf

我在基于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

的Web.Config

 <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>

1 个答案:

答案 0 :(得分:0)

捅了一下:

[Serializable]
[DataContract]

确保将这些属性放在InitiativeData

using System.Collections.ObjectModel;
using System.Runtime.Serialization;