【发布时间】:2010-11-02 08:04:30
【问题描述】:
我创建了一个 WCF 服务并且正在运行。目前这是一个非常基础的服务,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
[ServiceContract(Namespace = "TestServiceNameSpace")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyTestService
{
[OperationContract]
public MyNamespace.MyCompoundType ReturnMyCompoundType()
{
return new MyNamespace.MyCompoundType { DateVal = DateTime.Now, IntegerVal = 256, StringVal = "Pedro's test" };
}
}
下面是 MyCompoundType 类
using System.Runtime.Serialization;
using System;
using System.ComponentModel;
namespace MyNamespace
{
[DataContract]
public class MyCompoundType : IMyCompoundType
{
[DataMember]
public int IntegerVal { get; set; }
[DataMember]
public string StringVal { get; set; }
[DataMember]
public DateTime DateVal { get; set; }
}
}
现在,当我通过转到http://localhost/MyTestService.svc/jsdebug(然后我用它来进行 Ajax 调用)查看此服务的 JS 文件时,我注意到没有为 MyCompoundType 创建代理。所以,当我包含这个 JS 文件时,一切正常,我可以调用服务,但我不能声明 MyCompoundType 类型的 javascript 变量(即代理类型)。这甚至可能吗?这样做的一个主要部分是,我们将在 javascript 中使用智能感知功能,以避免像有人输入这样的错误:
var mycompundTypeReturn = returnValueFromWCFCall;
alert(mycompoundTypeReturn.StrVal); //this will give us an error because mycompoundTypeReturn.StrVal does not exist, only mycompoundTypeReturn.StringVal exists
是否可以使用 svcutil.exe 生成 JS 代理文件并指定更多详细信息?有什么我错过的属性吗?这甚至可能吗?这对使用 WCF 是否有意义?
任何帮助都将不胜感激,甚至“您在浪费时间,这是不可能的,您错过了 WCF 的重点”回复将不胜感激。
谢谢
【问题讨论】:
标签: javascript ajax wcf proxy