环境是win7 x64+vs2010用的spring.net+nhibernate
大体架构如图契约和实现在service层,web层通过spring.net管理的服务,通过jquery调用
现在问题是这样:
服务实现PrivateCmsService.cs的方法,返回bool,string这样的简单类型页面可以得到正确的返回值
如果返回值是类则不执行,直接500 System.ServiceModel.ServiceActivationException,如果返回list<T>通过断点发现执行正常,但是执行完毕没有返回值,firebug看状态是Aborted
实在不知道该咋整,网上也没搜到相关的例子,但是不用spring.net,单纯的wcf服务可以返回List《t》啊
web.config配置如下
<system.serviceModel>
    <services>
      <service name="PrivateCmsService" behaviorConfiguration="EnableMetadataBehaviors">
        <endpoint address="" binding="webHttpBinding" contract="CMS.Service.Contract.IPrivateCmsServiceContract" behaviorConfiguration="PrivateCmsServiceBehavior"/>
        <!--bindingConfiguration="HttpJsonpBinding"-->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="PrivateCmsServiceBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>        
        <behavior name="EnableMetadataBehaviors">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<bindings>
      <webHttpBinding>
        -->
    <!--crossDomainScriptAccessEnabled make the WCF 4 service support the JSONP-->
    <!--
        <binding name="HttpJsonpBinding" crossDomainScriptAccessEnabled="true" />
      </webHttpBinding>
    </bindings>-->
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

解决方案 »

  1.   

    返回值是string正常,这个都对
    但是返回值是List<t>和类则出错,难道只能返回string和bool int之流的数据类型?
      

  2.   

    试下string[] 返回的是不是ArrayofString
      

  3.   

    500 看样子是序列化出错了。IPrivateCmsServiceContract 贴出来看看?
      

  4.   


    接口定义
    [OperationContract]
    [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    string[] GetNewsKindByApp(int appIndex);//IList<NewsKind>实现类的声明
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    // [JavascriptCallbackBehavior(UrlParameterName = "jsoncallback")]
    public class PrivateCmsService : IPrivateCmsServiceContract
      

  5.   

    哦?REST WCF 的。没有定义uriTemplate?[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest,
    UriTemplate = "GetNewsKindByApp/{appindex}")]
    List<NewsKind> GetNewsKindByApp(string appIndex);
      

  6.   

    哦对了,NewsKind 是POCO对象吗?还是EntityObject。
      

  7.   

    还是500 System.ServiceModel.ServiceActivationException

    poco类是啥意思
    using System;
    using Iesi.Collections.Generic;namespace CMS.Domain
    {
        [Serializable]
        public partial class NewsKind : StatusChange
        {
            public NewsKind()
            {
                News = new HashedSet<News>();
            }
            public virtual NewsKindId NewsKindId
            {
                get;
                set;
            }
            public virtual string KindName
            {
                get;
                set;
            }
            public virtual string StatusCode
            {
                get;
                set;
            }
            public virtual App App
            {
                get;
                set;
            }
            public virtual ISet<News> News
            {
                get;
                set;
            }        public override bool Equals(object obj)
            {
                if (ReferenceEquals(this, obj))
                    return true;            return Equals(obj as NewsKind);
            }        public virtual bool Equals(NewsKind obj)
            {
                if (obj == null) return false;            if (Equals(NewsKindId, obj.NewsKindId) == false)
                    return false;            if (Equals(KindName, obj.KindName) == false)
                    return false;            if (Equals(StatusCode, obj.StatusCode) == false)
                    return false;            return true;
            }        public override int GetHashCode()
            {
                int result = 1;
                result = (result * 397) ^ (NewsKindId != null ? NewsKindId.GetHashCode() : 0);
                result = (result * 397) ^ (KindName != null ? KindName.GetHashCode() : 0);
                result = (result * 397) ^ (StatusCode != null ? StatusCode.GetHashCode() : 0);
                return result;
            }
        }
    }
      

  8.   

    下班了,明天再来
    先感谢一下子夜和JustACoder
      

  9.   

    POCO就是特纯洁的CLR类型。只有简单类型的get,set属性。这样你先做个简单的类,返回下,以排除这个问题:
    public class POCO_NewsKind
    {
       public virtual string KindName {get;set;}
       public virtual string StatusCode {get;set;}
    }
    另外,参考:http://blog.csdn.net/fangxinggood/archive/2011/05/28/6452549.aspx
    以前我直接返回 EntityObject 的时候,会返回 504 的错误,估计类似。
      

  10.   


    不过ServiceActivationException,msdn解释说是此异常派生自 CommunicationException,它表示在终结点间进行通信时可能引发的一类可恢复的错误,并且需要可靠的 Windows Communication Foundation (WCF) 客户端和服务应用程序来进行处理。若要防止更一般的 CommunicationException 处理程序捕获更具体的 ActionNotSupportedException,请在处理 CommunicationException 之前捕获此异常。不过我都不知道在那去catch,调试也没见蹦出异常来
      

  11.   

    昨天下乡六一去了,哈哈,今天继续
    项目里有个简单的类OpSecurity只有get和set方法,我把equals和gethashcode等方法都去掉了重试也还是500错误
      

  12.   

    对了,你的.svc文件的up是用的WebServiceHostFactory么?
    <%@ ServiceHost Language="C#" Debug="true" Service="WcfRESTfulSvc1.TaskService" CodeBehind="TaskService.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>
      

  13.   

    <%@ ServiceHost Language="C#" Debug="true" Service="PrivateCmsService" Factory="Spring.ServiceModel.Activation.ServiceHostFactory" %>用的spring管理的wcf
      

  14.   

    hoho问题在这哦,改下、这个和spring没关系你要想让WCF支持REST,并指定是json/xml序列化response,需要配合WebHttpBinding和WebServiceHostFactory哦
      

  15.   

    看你的类型也还不像 EntityObject 那么复杂,而且就算使用复杂类型只要是可序列化的。
    Xml格式的都不会有问题。比如:EntityObject只是序列化成json会失败。你可以先试试你现在的类(应该没事,因为之前我也没想到是Factory的事,所以让你试试POCO的)
    如果不行,那么就需要改写这个实体类了。
      

  16.   

    newskind用了Serializable标记,也不能说是复杂了,只是个联合主键,有几个ilst的成员现在用getnewsKind的话,firefug看还是abortedPOST http://www.mycms.com:85/PrivateCmsService.svc/GetNewsKindByApp HTTP/1.1
    Accept: application/json, text/javascript, */*; q=0.01
    Content-Type: text/json;
    X-Requested-With: XMLHttpRequest
    Referer: http://www.mycms.com:85/ccenter/opmanager.aspx
    Accept-Language: zh-cn
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
    Host: www.mycms.com:85
    Content-Length: 17
    Connection: Keep-Alive
    Pragma: no-cache
    Cookie: ASP.NET_SessionId=w22dj54gi1gz4hdd30qlvna0{"appIndex":"28"}
    HTTP/1.1 504 Fiddler - Receive Failure
    Content-Type: text/html
    Connection: close
    Timestamp: 10:39:19.853ReadResponse() failed: The server did not return a response for this request.