【发布时间】:2010-12-04 00:21:45
【问题描述】:
好的,我一定错过了一些非常简单的东西,因为我已经搜索了好几天,在那里查看了几十个答案,在这里,我就是无法让它工作,不管我是什么'我试过了。当通过普通 HTTP 调用时,该服务工作得非常好。
这是我们的设置...我们有一个域 http://www.mydomain.com 。我们从 thawte 在该域上安装了 SSL 证书,就像我们保护电子商务网站一样。这一切都很好,我可以去 https://www.mydomain.com 并且它工作正常。 我在 Windows Server 2003 R2 上运行 VS2008、.NET 3.5 站点。
现在,我向我的网站添加了启用 Silverlight 的 WCF 服务,我想通过 SSL 与之通信。如果我浏览到 https://www.mydomain.com/myservice.svc,它会按预期显示 WSDL 描述性“您已创建服务”页面,显示使用
创建您的客户端svcutil.exe https:// ...
编辑: 我意识到 wsdl 文件中为 svcutil 显示的 url 实际上指向 Web 服务器的物理框名称,而不是正确的域。所以我通过 this blog posting 中显示的步骤使用 adsutil 脚本在 IIS 中更新网站的 SecureBinding。现在 wsdl 文件显示了正确的 SSL 地址,但我仍然得到同样的错误。
现在我尝试将我的 Silverlight 应用程序连接到它,但它不起作用,在异步调用的结果中返回异常,说明“远程服务器返回错误:NotFound。我读过的一些博客都谈到了通过创建一个测试 Windows 应用程序并尝试从中引用它来将其缩小到 Silverlight 问题。好吧,我做到了,甚至在一个常规的 Windows 应用程序中尝试访问通过 SSL 服务我得到一个异常说明:
System.ServiceModel.EndpointNotFoundException:
There was no endpoint listening at https://www.mydomain.com/mysubdir/myservice.svc that could accept the message.
This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details. --->
System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
尽管我使用 HTTPS 方案明确地将服务引用添加到 Windows 应用程序,并且它正确获取所有方法并在编辑器中的 Intellisense 中显示它们。
请注意,这是一项不需要用户明确登录的服务。我将在我的 SOAP 信封中发送自定义标头以验证请求是否来自我们的应用程序,并且我只想防止掠夺者嗅探线路并挑选出自定义标头。
现在到代码,我必须只是有一些愚蠢的小设置错误,因为从我读过的所有内容来看,这应该是一个相当简单的练习。
首先,我的服务的代码隐藏类装饰有以下属性:
<ServiceBehavior(AddressFilterMode:=AddressFilterMode.Any)>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
服务器上我的 web.config 的 ServiceModel 部分如下所示:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding">
<security mode="Transport">
<transport clientCredentialType ="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="standingsBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://www.mydomain.com:80"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="standingsBehavior" name="lijslwebdata">
<endpoint address="" binding="basicHttpBinding" contract="lijslwebdata"/>
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
</service>
</services>
</system.serviceModel>
我的 Windows 应用程序中 app.config 的 ServiceModel 部分如下所示:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_lijslwebdata" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://www.mydomain.com/mysubdir/myservice.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_lijslwebdata"
contract="xdata.lijslwebdata" name="BasicHttpBinding_lijslwebdata" />
</client>
</system.serviceModel>
【问题讨论】:
-
一个问题,baseAddressPrefixFilters 是否需要以某种方式设置为 HTTPS??
-
我也对这个很感兴趣。我目前有一个 HTTP WCF 服务,并且在提供 HTTPS 选项时会遇到麻烦。请记得发布您的结果! :)
标签: ssl https wcf wcf-binding