【发布时间】:2012-12-11 22:29:40
【问题描述】:
我有一个很好的 WCF REST-ful JSON 服务,它运行良好。当我尝试将其用于 HTTPS 时,就会出现问题。 Web.config如下:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="StreamedRequestWebBinding" bypassProxyOnLocal="true" useDefaultWebProxy="false" hostNameComparisonMode="WeakWildcard" sendTimeout="10:15:00" openTimeout="10:15:00" receiveTimeout="10:15:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="StreamedRequest">
<security mode="Transport">
<transport clientCredentialType = "None" />
</security>
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="WcfRESTFullJSON.Service1" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract="WcfRESTFullJSON.IService1" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<!--Him-->
<webHttp automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
我在 IIS 上配置了一个自制的证书。 在我的客户端上:
WebClient WC;
...
WC.UploadData(URL, "POST", asciiBytes);
我们得到了什么:
The remote server returned an error: (500) Internal Server Error.
可能是什么问题?
【问题讨论】:
-
您的服务中有任何登录方式吗?你也可以enable WCF tracing看看发生了什么。
-
System.ServiceModel.FaultException:由于 EndpointDispatcher 的 AddressFilter 不匹配,消息 ... 无法在接收方处理。检查发送方和接收方的 EndpointAddresses 是否一致... 当 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' 在配置中设置为 true 时,端点需要指定相对地址。如果您在端点上指定相对侦听 URI,则地址可以是绝对地址。要解决此问题,请为端点指定一个相对 uri..
-
... 如何指定相对地址?非常感谢。
-
现在剩下的错误是:System.InvalidOperationException:找不到与绑定 MetadataExchangeHttpsBinding 的端点的方案 https 匹配的基地址。注册的基地址方案是 [http]。
-
在 IIS 中为您的站点添加 https 绑定。