【问题标题】:Ajax Enabled Wcf Service cant find specific methodAjax Enabled Wcf Service 找不到具体方法
【发布时间】:2012-09-19 11:07:01
【问题描述】:

我有奇怪的 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 的 WebService 发送数组?

【问题讨论】:

  • 我删除了 asp classic 标签,这是一个 asp.net 问题。
  • 答案很简单:将 Linq DB 上的 Seriliazation 设置为单向

标签: c# javascript asp.net web-services


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多