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