【发布时间】:2020-07-15 12:25:48
【问题描述】:
我想通过 mono 托管具有多个合同的 WCF Rest 服务,每个合同都在单独的部分类中实现。我阅读了许多关于类似问题的帖子,但没有针对单声道的解决方案。我合并或至少测试了我能找到的所有建议,现在我的代码看起来很像其他解决方案,但不起作用。
该应用程序在我的本地机器上成功运行,但一旦我通过单声道部署它就会引发错误。
Service 'MyWebServiceEndpoint' 实现了多种 ServiceContract 类型,配置文件中没有定义端点。
这是合同的端点之一。所有其他人都非常喜欢这个。它们都是实现另一个合同的部分类 MyWebServiceEndpoint 。
namespace MyServer.MyEndPoints {
public partial class MyWebServiceEndpoint : INotificationEndpoint {
public string GetNotifications(int limit) {
// Do stuff
}
}
[ServiceContract]
public interface INotificationEndpoint {
[OperationContract]
[WebGet]
string GetNotifications(int limit);
}
}
我的 App.config 看起来像这样。我删除了 IP 和端口,因为它们是服务器地址。
<system.serviceModel>
<services>
<service name="MyServer.MyEndPoints.MyWebServiceEndpoint" behaviorConfiguration="WebService.EndPoint">
<host>
<baseAddresses>
<add baseAddress="http://ip:port>"/>
</baseAddresses>
</host>
<endpoint address="/message"
binding="webHttpBinding"
contract="MyServer.MyEndPoints.IMessageEndpoint"
behaviorConfiguration="WebBehavior"/>
<endpoint address="/music"
binding="webHttpBinding"
contract="MyServer.MyEndPoints.IMusicEndpoint"
behaviorConfiguration="WebBehavior"/>
<endpoint address="/notification"
binding="webHttpBinding"
contract="MyServer.MyEndPoints.INotificationEndpoint"
behaviorConfiguration="WebBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WebService.EndPoint">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
我像这样在 C# 中打开服务。
WebServiceHost = new WebServiceHost(typeof(MyWebServiceEndpoint));
WebServiceHost.Open();
我在单声道上收到的错误消息是:
Unhandled Exception:
System.InvalidOperationException: Service 'MyWebServiceEndpoint' implements multiple ServiceContract
types, and no endpoints are defined in the configuration file. WebServiceHost can set up default
endpoints, but only if the service implements only a single ServiceContract. Either change the
service to only implement a single ServiceContract, or else define endpoints for the service
explicitly in the configuration file. When more than one contract is implemented, must add base
address endpoint manually
我希望你有一些提示或有人知道如何解决这个问题。感谢您阅读到这里。
【问题讨论】:
标签: rest wcf configuration mono endpoint