c# – WCF配置地狱?
我讨厌WCF设置端点,行为等等.我相信所有这些都应该自动执行.所有我想做的是从我的WCF服务返回
JSON结果.这是我的配置:
<system.serviceModel> <bindings> <webHttpBinding> <binding name="default"/> </webHttpBinding> </bindings> <services> <service name="HighOnCodingWebApps.ZombieService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint address="" binding="webHttpBinding" bindingConfiguration="default" contract="HighOnCodingWebApps.IZombieService" behaviorConfiguration="webScriptEnablingBehavior"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name="webScriptEnablingBehavior"> <enableWebScript/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyServiceTypeBehaviors"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="false"/> 我有以下服务实现: public class ZombieService : IZombieService { [WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json,UriTemplate = "KnownZombies")] public Zombie GetZombie() { return new Zombie() { Name = "Mohammad Azam"}; } } public class Zombie { public string Name { get; set; } } 当我访问http:// localhost:22059 / ZombieService / KnownZombies说出以下消息: 使用’UriTemplate’的端点不能与’System.ServiceModel.Description.WebScriptEnablingBehavior’一起使用. 如果我从web.config中删除WebScriptEnablingBehavior我得到以下错误:
更新1: 我将配置更新为: <system.serviceModel> <bindings> <webHttpBinding> <binding name="default"/> </webHttpBinding> </bindings> <services> <service name="HighOnCodingWebApps.ZombieService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint address="http://localhost:22059/ZombieService.svc" binding="webHttpBinding" bindingConfiguration="default" contract="HighOnCodingWebApps.IZombieService" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="SomeBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyServiceTypeBehaviors"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> 现在当我访问http:// localhost:22059 / ZombieService.svc / KnownZombies我在浏览器中收到以下消息:
解决方法
看看
this SO question.
编辑:由于您没有为服务指定地址,请尝试点击:http://localhost:22059/ZombieService.svc/KnownZombies(使用.svc). 我也认为你需要< webHttp />行为添加到指定的端点行为. 编辑:尝试将端点定义更改为: <service name="HighOnCodingWebApps.ZombieService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="SomeBehavior" bindingConfiguration="default" contract="HighOnCodingWebApps.IZombieService" /> </service> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |