繁体   English   中英

启用Ajax的Wcf服务找不到特定的方法

[英]Ajax Enabled Wcf Service cant find specific method

我有Webservice的奇怪行为。

现在,webservice看起来像:

[ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1
    {
        // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
        // To create an operation that returns XML,
        //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
        //     and include the following line in the operation body:
        //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        [OperationContract]
        public string DoWork()
        {
            // Add your operation implementation here
            return "Hello there";
        }

        // Add more operations here and mark them with [OperationContract]
    }

而且我可以在JS中毫无问题地从中读取:

   <script>




        function doWork() {
            Service1.DoWork(onSuccess, onFailure);
        }

        function onSuccess(result) {
            document.getElementById('txtValueContainer').value = result;
        }

        function onFailure(result) {
            window.alert(result);
        }


</script>

但是,一旦我尝试发送其他东西,然后发送字符串,例如:

        [OperationContract]
        public Question[] OurServerOutput(string userid)
        {
            return Question.getQuestionsForUser(new Guid(userid)).ToArray();
        }

where 

        public static IEnumerable<Question> getQuestionsForUser( Guid userGuid)
        {
            LinqConnectionDataContext context = new LinqConnectionDataContext();
            var query = from c in context.Questions where c.UidUser == userGuid select c;
            return query;

        }

Javascript无法再找到我的服务,并且出现错误:

Unhandled exception at line 132, column 13 in http://localhost/

0x800a1391 - Microsoft JScript runtime error: 'Service1' is undefined

如何通过启用Ajax的Web服务发送数组?

答案很简单:将Linq DB上的Seriliazation设置为Unidirectional

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM