WCF配置地狱? [英] WCF Configuration Hell?
问题描述
我讨厌WCF设置与终点,行为等,我相信所有的这些东西都应该自动执行。所有我想要做的是从我的WCF服务返回JSON结果。下面是我的配置:
< system.serviceModel>
<绑定>
<的WebHttpBinding>
<绑定名称=默认/>
< /的WebHttpBinding>
< /绑定>
<服务>
<服务名称=HighOnCodingWebApps.ZombieService
behaviorConfiguration =MyServiceTypeBehaviors>
<端点地址=绑定=的WebHttpBinding
bindingConfiguration =默认
合同=HighOnCodingWebApps.IZombieService
behaviorConfiguration =webScriptEnablingBehavior/>
< /服务>
< /服务>
<行为>
< endpointBehaviors>
<行为NAME =webScriptEnablingBehavior>
< enableWebScript />
< /行为>
< / endpointBehaviors>
< serviceBehaviors>
<行为NAME =MyServiceTypeBehaviors>
< serviceMetadata httpGetEnabled =真/>
< /行为>
< / serviceBehaviors>
< /行为>
< serviceHostingEnvironment aspNetCompatibilityEnabled =FALSE/>
和我有以下服务实现:
公共类ZombieService:IZombieService
{
[WebInvoke(方法=GET,
ResponseFormat = WebMessageFormat.Json,
UriTemplate =KnownZombies)]
公共僵尸GetZombie()
{
返回新的僵尸(){名称=穆罕默德·阿扎姆};
}
}
公共类僵尸
{
公共字符串名称{;组; }
}
当我访问的http://本地主机:22059 / ZombieService / KnownZombies
表示以下信息:
端点不能使用与'System.ServiceModel.Description.WebScriptEnablingBehavior'
如果我在web.config中我得到以下错误删除WebScriptEnablingBehavior:
使用的消息 HTTP://本地主机:22059 / ZombieService.svc / KnownZombies不能 在接收器处进行处理时,由于一个错配AddressFilter在 EndpointDispatcher。检查发送者和接收者的 EndpointAddresses同意。
更新1:
我更新了配置,以这样的:
< system.serviceModel>
<绑定>
<的WebHttpBinding>
<绑定名称=默认/>
< /的WebHttpBinding>
< /绑定>
<服务>
<服务名称=HighOnCodingWebApps.ZombieService
behaviorConfiguration =MyServiceTypeBehaviors>
<端点地址=HTTP://本地主机:22059 / ZombieService.svc绑定=的WebHttpBinding
bindingConfiguration =默认
合同=HighOnCodingWebApps.IZombieService
/>
< /服务>
< /服务>
<行为>
< endpointBehaviors>
<行为NAME =SomeBehavior>
< webHttp />
< /行为>
< / endpointBehaviors>
< serviceBehaviors>
<行为NAME =MyServiceTypeBehaviors>
< serviceMetadata httpGetEnabled =真/>
< /行为>
< / serviceBehaviors>
< /行为>
< /system.serviceModel>
现在当我访问的http://本地主机:22059 / ZombieService.svc / KnownZombies
我得到在浏览器中出现以下消息:
使用的消息 HTTP://本地主机:22059 / ZombieService.svc / KnownZombies不能 在接收器处进行处理时,由于一个错配AddressFilter在 EndpointDispatcher。检查发送者和接收者的 EndpointAddresses同意。
看看的这太问题。
编辑:既然你不指定地址为您服务,尽量击中:<一href="http://localhost:22059/ZombieService.svc/KnownZombies">http://localhost:22059/ZombieService.svc/KnownZombies (与的.svc)。
我还认为你需要的&LT; webHttp /&GT;
行为添加到您指定的终结点行为
编辑:试着改变你的终点定义的:
&LT;服务
NAME =HighOnCodingWebApps.ZombieService
behaviorConfiguration =MyServiceTypeBehaviors&GT;
&LT;端点
地址=
绑定=的WebHttpBinding
behaviorConfiguration =SomeBehavior
bindingConfiguration =默认
合同=HighOnCodingWebApps.IZombieService/&GT;
&LT; /服务&GT;
I hate WCF setup with endpoints, behaviors etc. I believe all these things should be performed automatically. All I want to do is to return JSON result from my WCF service. Here is my configuration:
<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"/>
And I have the following service implementation:
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; }
}
When I visit http://localhost:22059/ZombieService/KnownZombies
says the following message:
Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.
If I remove the WebScriptEnablingBehavior from the web.config I get the following error:
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.
UPDATE 1:
I updated the configuration to this:
<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>
Now when I visit http://localhost:22059/ZombieService.svc/KnownZombies
I get the following message in the browser:
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.
Take a look at this SO question.
Edit: Since you're not specifying an address for your service, try hitting: http://localhost:22059/ZombieService.svc/KnownZombies (with the .svc).
I also think you need the <webHttp />
behavior added to your specified endpoint behavior.
Edit: Try changing your endpoint definition to this:
<service
name="HighOnCodingWebApps.ZombieService"
behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint
address=""
binding="webHttpBinding"
behaviorConfiguration="SomeBehavior"
bindingConfiguration="default"
contract="HighOnCodingWebApps.IZombieService" />
</service>
这篇关于WCF配置地狱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!