【发布时间】:2014-04-17 14:40:23
【问题描述】:
我在关注这个tutorial,在完成上一个教程后也遇到了这个article。
让我好奇的是[ServiceContractAttribute]。看到文章里的[ServiceContract]没有Namespace,但是教程有。
所以我继续将[ServiceContract(Namespace="SandwichServices")] 更改为[ServiceContract],但是当我运行应用程序并单击按钮时,出现异常:Uncaught ReferenceError: SandwichServices is not defined。
所以我想知道,
- 除了还原更改之外,还有其他方法可以解决此错误吗?也许 Web.config 是答案,但我不确定我是否走在正确的轨道上。
- 两个
[ServiceContractAttribute]有什么区别?从我的角度来看,接口似乎不需要Namespace,但我说的对吗?
Web.config 文件内容:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SandwichServices.CostServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="SandwichServices.CostService">
<endpoint address=""
behaviorConfiguration="SandwichServices.CostServiceAspNetAjaxBehavior"
binding="webHttpBinding"
contract="SandwichServices.CostService" />
</service>
</services>
</system.serviceModel>
【问题讨论】:
-
要回答第一个问题,您能否将您的 web.config 添加到问题中,这可能是配置问题。
-
您是否更新了您的服务参考?
-
@PeterB,抱歉,尝试添加部分 Web.config,但在格式化代码时遇到问题。