好的,我肯定是在这里错过了某些非常简单的东西,因为我已经搜索了好几天,在那里看了数十个答案,以及在SO和这里看了数十个答案,但无论我尝试什么,我都无法使它工作。当以纯HTTP方式调用服务时,该服务完全正常工作。
这是我们的设置...我们有一个域名,http://www.mydomain.com。我们已经在该域上安装了来自thawte的SSL证书,就像我们在保护电子商务站点时那样。这一切都正常工作,我可以访问 https://www.mydomain.com,并且它可以正常工作。 我正在运行VS2008,.NET 3.5站点,运行在Windows Server 2003 R2上。
现在,我向我的站点添加了一个启用Silverlight的WCF服务,我希望通过SSL与其通信。如果我浏览到https://www.mydomain.com/myservice.svc,它会按预期显示WSDL描述性的“您已创建了一个服务”页面,其中显示要使用以下代码创建客户端:
svcutil.exe https:// ...
编辑:我意识到WSDL文件中显示的svcutil网址实际上指向Web服务器的物理框名,而不是正确的域名。因此,我按照这篇博客文章中所示的步骤,使用adsutil脚本更新IIS中网站的SecureBinding。现在,wsdl文件显示了正确的SSL地址,但我仍然收到相同的错误。
现在我尝试将我的Silverlight应用程序连接到它,但它不起作用,并在异步调用结果中返回一个异常,声明“远程服务器返回错误:未找到”。许多博客都谈到通过创建测试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应用程序中,并且它正确获取所有方法并在编辑器中显示它们,但情况仍然如此。
请注意,这是一项不需要用户明确登录的服务。我将在我的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>