我的WCF服务应用程序通过http和https工作,但是,当我在客户端向其添加服务引用(使用https url)时,Visual Studio 2010将配置文件中的端点设置为http。它似乎并不像将配置端点更改为https那么简单,因为幕后有多个文件使用xsd进行操作并引用http端点。如何设置我的服务/客户端以强制https以便正确设置端点?
当我尝试手动更改配置文件中的端点并将安全模式设置为“Transport”时,我收到此错误:
但是,我可以在IE中看到该端点,并在本地进行调试。在我使用https添加我的服务引用并搜索解决方案的http等效之后,它会找到一个引用http的wsdl文件,一个configuration.svcinfo和一个使用http url而不是https的configuration91.svcinfo异常消息:没有端点正在侦听 https://myservice/AvailabilityService.svc可以接受 信息。这通常是由错误的地址或SOAP操作引起的。 有关更多详细信息,请参阅InnerException(如果存在)。
这是我的服务器端配置:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
..和客户端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAvailabilityService" 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://myservice/AvailabilityService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAvailabilityService"
contract="PaymentAvailabilityService.IAvailabilityService"
name="BasicHttpBinding_IAvailabilityService" />
</client>
</system.serviceModel>
也许我最好手动使用代码中的服务?
答案 0 :(得分:30)
您需要更改绑定以使用传输安全性来使用HTTPS
您的服务器端绑定应配置为https以及客户端:
<bindings>
<basicHttpBinding>
<binding name="httpsBinding" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="yourNamespace.YourService" behaviorConfiguration="yourBehaviors">
<endpoint contract="yourNamespace.YourService" binding="basicHttpBinding" bindingConfiguration="httpsBinding" />
</service>
</services>