最近我开始在 C#(WCF 服务应用程序)中创建一个 Rest-Service。目的是在带有 apache2 + mod-mono + https + basic auth 的 Debian 7 系统上使用它。一切都在使用http。但我可以做我想做的事.. 它不适用于 https。我总是收到错误消息“请求的侦听 uri 方案必须是 http,但是是 https。” 并且不明白出了什么问题。我想我做了所有在网络上的各种博客和教程中描述的事情。
我正确配置了 https,创建了自签名证书等,事实上,https 本身正在正常工作。但与服务无关。我还尝试在带有 IIS-Express 7.5 的 Win7-Machine 上使用 https 服务,这就像一个魅力。它必须与 Linux/Mono/Apache 有关。
以下是我的配置文件。我希望有一个人可以帮助我 :(
每日问候
网页配置
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"
targetFramework="4.0">
</compilation>
<customErrors mode="Off"/>
<pages controlRenderingCompatibilityVersion="3.5"
clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<services>
<service name="RestService.RestServiceImpl"
behaviorConfiguration="ServiceBehaviour">
<endpoint address=""
binding="webHttpBinding"
contract="RestService.IRestServiceImpl"
bindingConfiguration="webHttpTransportSecurity"
behaviorConfiguration="webHttpBindingBehavior" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="false"
httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBindingBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
</configuration>
Apache 的站点配置
<IfModule mod_ssl.c>
<VirtualHost *:443>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
SSLOptions StrictRequire
SSLProtocol all -SSLv2
MonoServerPath wcs.mydomain.de "/usr/bin/mod-mono-server4"
MonoDebug wcs.mydomain.de true
MonoSetEnv wcs.mydomain.de MONO_IOMAP=all
MonoAutoApplication disabled
MonoApplications wcs.mydomain.de "/api:/var/www/wcs"
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
<Location /api>
SSLRequireSSL
Options FollowSymLinks
Allow from all
Order allow,deny
MonoSetServerAlias wcs.mydomain.de
SetHandler mono
AuthType Basic
AuthName "Authorization required"
AuthUserFile /etc/apache2/htpasswd
Require valid-user
</Location>
</VirtualHost>
编辑
附加信息,希望有人可以利用它并看到我的错。
版本信息
Version information: Mono Runtime Version: 2.10.8.1 (Debian 2.10.8.1-8); ASP.NET Version: 4.0.30319.1
完整的堆栈跟踪
System.ArgumentException: Requested listen uri scheme must be http, but was https.
at System.ServiceModel.Channels.Http.HttpChannelListener`1[System.ServiceModel.Channels.IReply Channel]..ctor (System.ServiceModel.Channels.HttpTransportBindingElement source, System.ServiceModel.Channels.BindingContext context) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[IReplyChannel ] (System.ServiceModel.Channels.BindingContext context) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[IReplyChannel] () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.BindingElement.BuildChannelListener[IReplyChannel] (System.ServiceModel.Channels.BindingContext context) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.WebMessageEncodingBindingElement.BuildChannelListener[IReplyCh annel] (System.ServiceModel.Channels.BindingContext context) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[IReplyChannel] () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.Binding.BuildChannelListener[IReplyChannel] (System.Uri listenUriBaseAddress, System.String listenUriRelativeAddress, ListenUriMode listenUriMode, System.ServiceModel.Channels.BindingParameterCollection parameters) [0x00000] in <filename unknown>:0
at System.ServiceModel.DispatcherBuilder.BuildListener (System.ServiceModel.Description.ServiceEndpoint se, System.ServiceModel.Channels.BindingParameterCollection pl) [0x00000] in <filename unknown>:0
at System.ServiceModel.DispatcherBuilder.BuildChannelDispatcher (System.Type serviceType, System.ServiceModel.Description.ServiceEndpoint se, System.ServiceModel.Channels.BindingParameterCollection commonParams) [0x00000] in <filename unknown>:0
at System.ServiceModel.ServiceHostBase.InitializeRuntime () [0x00000] in <filename unknown>:0
at System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.SvcHttpHandler.EnsureServiceHostCore () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.SvcHttpHandler.EnsureServiceHost () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.SvcHttpHandler.ProcessRequest (System.Web.HttpContext context) [0x00000] in <filename unknown>:0
at System.Web.HttpApplication+<Pipeline>c__Iterator6.MoveNext () [0x00000] in <filename unknown>:0
at System.Web.HttpApplication.Tick () [0x00000] in <filename unknown>:0
IRestServiceImpl.cs
using System.ServiceModel;
using System.ServiceModel.Web;
namespace RestService
{
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "info")]
string Info();
}
}
RestServiceImpl.svc
<%@ ServiceHost Language="C#" Debug="true" Service="RestService.RestServiceImpl" CodeBehind="RestServiceImpl.svc.cs" %>
RestServiceImpl.svc.cs
namespace RestService
{
public class RestServiceImpl : IRestServiceImpl
{
#region IRestServiceImpl Members
public string Info()
{
return "This is the Rest-Service for a WCS";
}
#endregion
}
}
mod_mono.conf
AddType application/x-asp-net .svc .aspx .ashx .asmx .ascx .asax .config
DirectoryIndex index.aspx
Include /etc/mono-server4/mono-server4-hosts.conf
编辑-2
正如下面的 knocte 建议的那样,我升级到了 Mono 3,但仍然遇到同样的错误。
System.ArgumentException - Requested listen uri scheme must be http, but was https.
版本信息
Version Information: 3.0.12 (master/574dbc8 Wed May 29 20:34:12 CEST 2013); ASP.NET Version: 4.0.30319.17020
堆栈跟踪
at System.ServiceModel.Channels.Http.HttpChannelListener`1[System.ServiceModel.Channels.IReplyChannel]..ctor (System.ServiceModel.Channels.HttpTransportBindingElement source, System.ServiceModel.Channels.BindingContext context) [0x00126] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpChannelListener.cs:71
at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[IReplyChannel] (System.ServiceModel.Channels.BindingContext context) [0x00000] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpTransportBindingElement.cs:246
at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[IReplyChannel] () [0x00020] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/BindingContext.cs:161
at System.ServiceModel.Channels.BindingElement.BuildChannelListener[IReplyChannel] (System.ServiceModel.Channels.BindingContext context) [0x00011] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/BindingElement.cs:63
at System.ServiceModel.Channels.WebMessageEncodingBindingElement.BuildChannelListener[IReplyChannel] (System.ServiceModel.Channels.BindingContext context) [0x0001d] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncodingBindingElement.cs:126
at System.ServiceModel.Channels.BindingContext.BuildInnerChannelListener[IReplyChannel] () [0x00020] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/BindingContext.cs:161
at System.ServiceModel.Channels.Binding.BuildChannelListener[IReplyChannel] (System.Uri listenUriBaseAddress, System.String listenUriRelativeAddress, ListenUriMode listenUriMode, System.ServiceModel.Channels.BindingParameterCollection parameters) [0x00046] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Binding.cs:174
at System.ServiceModel.DispatcherBuilder.BuildListener (System.ServiceModel.Description.ServiceEndpoint se, System.ServiceModel.Channels.BindingParameterCollection pl) [0x00038] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:720
at System.ServiceModel.DispatcherBuilder.BuildChannelDispatcher (System.Type serviceType, System.ServiceModel.Description.ServiceEndpoint se, System.ServiceModel.Channels.BindingParameterCollection commonParams) [0x0005e] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:657
at System.ServiceModel.ServiceHostBase.InitializeRuntime () [0x000ad] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:460
at System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) [0x00006] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:567
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00006] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:170
at System.ServiceModel.Channels.CommunicationObject.Open () [0x00000] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:164
at System.ServiceModel.Channels.SvcHttpHandler.EnsureServiceHostCore () [0x00068] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/SvcHttpHandler.cs:138
at System.ServiceModel.Channels.SvcHttpHandler.EnsureServiceHost () [0x00016] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/SvcHttpHandler.cs:117
at System.ServiceModel.Channels.SvcHttpHandler.ProcessRequest (System.Web.HttpContext context) [0x00000] in /opt/mono-3.0/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/SvcHttpHandler.cs:75
at System.Web.HttpApplication+<Pipeline>c__Iterator3.MoveNext () [0x00dd7] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web/HttpApplication.cs:1368
at System.Web.HttpApplication.Tick () [0x00000] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web/HttpApplication.cs:932