暴露的WebHttpBinding端点WCF服务 [英] Expose webHttpBinding endpoint in a WCF service
问题描述
我创建了一个WCF服务,暴露三个端点这是basicHttpBinding的,和的wsHttpBinding的WebHttpBinding。这是我的实验与WCF测试服务。但是,每当我使用.svc文件添加服务引用,我只得到两(基本和WS)端点。似乎没有被暴露出于某种原因三分之一(webHttpBidning)终结点。
I created a WCF service and exposed three endpoints which are basicHttpBinding, wsHttpBinding and webHttpBinding. This is a test service for my experiments with WCF. But, whenever I add service reference using the .svc file, I only get two (basic and ws) endpoints. There doesn't seem to be a third (webHttpBidning) endpoint being exposed for some reason.
要重现此问题,创建一个WCF应用程序项目,删除服务1服务,添加新项> WCF服务名为TestService的,而配置文件更改为以下内容:
To reproduce this issue, create a WCF application project, delete the Service1 service, add new item > WCF service named TestService, and change the config file to the following :
<system.serviceModel>
<services>
<service name="WcfTestService.TestService" behaviorConfiguration="TestServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfTestService/TestService.svc"/>
</baseAddresses>
</host>
<endpoint address="basic"
binding="basicHttpBinding"
contract="WcfTestService.ITestService" />
<endpoint address="ws"
binding="wsHttpBinding"
contract="WcfTestService.ITestService" />
<endpoint address="web"
binding="webHttpBinding"
contract="WcfTestService.ITestService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TestServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
下面是ITestService代码的.cs:
Here is the code for ITestService.cs:
[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebInvoke]
Boolean ValidateUser(User user);
}
[DataContract]
public class User
{
[DataMember(Name = "Name")]
public String UserName { get; set; }
[DataMember]
public String Password { get; set; }
}
和TestService.svc
and for TestService.svc
public class TestService : ITestService
{
public bool ValidateUser(User user)
{
if (user.UserName == "User" && user.Password == "123")
{
return true;
}
return false;
}
}
我试过WebInvoke参数和WebGet参数的不同组合,但失败了。
I tried different combination of WebInvoke parameters and WebGet parameters, but failed.
谁能告诉我,为什么第三个端点没有显示在WSDL文件了?
Can anyone tell me why the third endpoint is not showing up in the WSDL file?
推荐答案
@decyclone:我已经成功地暴露webHttpBindings没有任何问题。但我发现,当它得到暴露了一些有趣的事情,当它不是!
@decyclone: I have successfully exposed webHttpBindings without any issue. But I found some interesting thing when it get exposed and when it not!
我可以看到网络的结合越来越暴露在WCF测试客户端。
I can see web binding getting exposed in Wcf Test Client.
下面是我的配置
<services>
<service behaviorConfiguration="TestWeb.Service2Behavior" name="TestWeb.Service2">
<endpoint address="" binding="wsHttpBinding" contract="TestWeb.Service2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="web" binding="webHttpBinding" contract="TestWeb.Service2">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
指向这里注意,其优良的工作使用VS2008与框架3.5,VS2010与Framework 3.5中,当我使用VS2010和框架4.0,然后我看不出在WCF测试客户端的WebHttpBinding越来越暴露出来,不过,我可以使用binidng做到在所有情况下HTTP POST。
Point to note here is, its working fine using VS2008 with Framework 3.5, VS2010 with Framework 3.5, when I use VS2010 and Framework 4.0 then I can't see WebHttpBinding getting exposed in WCF Test Client, however I can use that binidng to do http post in all cases.
我!假设在Framework 4.0的默认情况下不可见,即使我尝试让endpointDiscovery但仍没有运气
I assume that in Framework 4.0 its not visible by default, even I try enable endpointDiscovery but still no luck!
我已经涵盖在我的post
这篇关于暴露的WebHttpBinding端点WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!