0

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 で Read を取得できます。

   <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 経由で配列を送信するにはどうすればよいですか?

4

1 に答える 1

0

答えは非常に簡単でした。Linq DB のシリアル化を単方向に設定します。

于 2012-09-20T09:31:29.910 に答える