WCF Web服务-多种服务 [英] WCF Web Service - Multiple Services
问题描述
< system.serviceModel >
< 行为 >
< serviceBehaviors >
< 行为 名称 StdBehavior" < serviceMetadata =" true" >
< serviceDebug =" true" >
< /行为 >
< /serviceBehaviors >
< /行为 >
< 绑定 >
< basicHttpBinding < 绑定 =" secureBind" < 安全性 =" 运输" < 运输 =" 证书" / < /security >
< /binding >
< /basicHttpBinding >
< /bindings >
< 服务 >
< 服务 =" StdBehavior" 名称 LocalSvc" >
< 端点 =" A.ICrisSvc"
span> 名称 ="
span> 绑定 ="
地址 ="
/ >
< 端点 =" IMetadataExchange"
名称 ="
span> 绑定 ="
地址 ="
/ >
< /service >
< 服务 =" StdBehavior" 名称 DevSvc" >
< 端点 =" A.ICrisSvc"
span> 名称 ="
绑定 ="
bindingConfiguration ="
地址 ="
span> / >
< /service >
< 服务 =" StdBehavior" 名称 ProductionSvc" >
< 端点 =" A.ICrisSvc"
span> 名称 ="
span> 绑定 ="
bindingConfiguration ="
span> 地址 ="
span> / >
< /service >
< /服务 >
< /system.serviceModel >
当我尝试向桌面应用程序添加服务引用时,出现以下错误:
Service ''A.CrisSvc'' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
在我看来,我拥有所有需要存放在其中的东西.如果删除两个https服务,则可以添加引用.我在做什么错?
可以尝试在服务名称中添加命名空间(如果有)吗?
< 服务 行为配置 =" 名称 =" < /service > < 服务 =" 名称 Namespace.DevSvc " < /service > < 服务 =" 名称 Namespace.ProductionSvc " < /service >
我可以使用它,但是我不确定为什么.我最初是这样做的:
公共 class CrisSvc:ICrisSvc { // 网络方法在这里 } 公共 类 LocalSvc:CrisSvc { // 空类 } 公共 类 DevSvc:CrisSvc { // 空类 } 公共 类 ProdSvc:CrisSvc { // 空类 }
错误是针对基类的,所以我认为也许每个类都需要一个端点,即使它没有被直接使用,所以我将配置文件中的LocalSvc
引用更改为CrisSvc
,我能够成功添加服务参考.请注意,这有点使我的理论无所适从,因为每种服务对端点的要求都是如此.如果有人可以澄清这里发生的事情,我将不胜感激.
I''me developing a WCF web service. I want to be able to use it on my local box (for debugging purposes, and deploy it to two secure web sites. I''ve come up with the following service model configuration:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="StdBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding >
<binding name="secureBind">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="StdBehavior" name="LocalSvc">
<endpoint contract="A.ICrisSvc"
name="localEndpoint"
binding="wsHttpBinding"
address=""
/>
<endpoint contract="IMetadataExchange"
name="mexEndpoint"
binding="mexHttpBinding"
address="mex"
/>
</service>
<service behaviorConfiguration="StdBehavior" name="DevSvc">
<endpoint contract="A.ICrisSvc"
name="devEndpoint"
binding="basicHttpBinding"
bindingConfiguration="secureBind"
address="https://blah.mil/blah/CrisSvc"
/>
</service>
<service behaviorConfiguration="StdBehavior" name="ProductionSvc">
<endpoint contract="A.ICrisSvc"
name="prodEndpoint"
binding="basicHttpBinding"
bindingConfiguration="secureBind"
address="https://blah2.mil/blah2/CrisSvc"
/>
</service>
</services>
</system.serviceModel>
When I try to add a service reference to my desktop application, I get the following error:
Service ''A.CrisSvc'' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
It looks to me like I have everything in there that needs to be in there. If I remove the two https services, I can add the reference. What am I doing wrong?
Can you try adding Namespaces (if any) to your service name?
<service behaviorconfiguration="StdBehavior" name="Namespace.LocalSvc"> </service> <service behaviorconfiguration="StdBehavior" name="Namespace.DevSvc"> </service> <service behaviorconfiguration="StdBehavior" name="Namespace.ProductionSvc"> </service>
I got it to work, but I''m not sure why. I had originally done this:
public class CrisSvc : ICrisSvc { // web methods are here } public class LocalSvc : CrisSvc { // empty class } public class DevSvc : CrisSvc { // empty class } public class ProdSvc : CrisSvc { // empty class }
The error was for the base class, so I thought maybe every class needs an endpoint, even if it''s not directly used, so I changed theLocalSvc
reference in the config file to beCrisSvc
, and I was able to successfully add the service reference. Note that this kinda blew my theory out of the water regarding the requirement for an endpoint for every service. If anyone can clarify what''s happening here, I would be most appreciative.
这篇关于WCF Web服务-多种服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!