<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我得到以下错误:
The message with To
‘http://localhost:22059/ZombieService.svc/KnownZombies’ cannot be
processed at the receiver,due to an AddressFilter mismatch at the
EndpointDispatcher. Check that the sender and receiver’s
EndpointAddresses agree.
更新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我在浏览器中收到以下消息:
The message with To
‘http://localhost:22059/ZombieService.svc/KnownZombies’ cannot be
processed at the receiver,due to an AddressFilter mismatch at the
EndpointDispatcher. Check that the sender and receiver’s
EndpointAddresses agree.
解决方法
编辑:由于您没有为服务指定地址,请尝试点击:@L_403_2@(使用.svc).
我也认为你需要< webHttp />行为添加到指定的端点行为.
编辑:尝试将端点定义更改为:
<service name="HighOnCodingWebApps.ZombieService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="SomeBehavior" bindingConfiguration="default" contract="HighOnCodingWebApps.IZombieService" /> </service>