.net 使用 https 端点添加 WCF 服务引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8038703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding WCF Service Reference with https endpoint
提问by Chris Klepeis
My WCF service application works over http and https, however, when I add a service reference (with the https url) to it in my client, Visual Studio 2010 sets the endpoint in the config file to http. It doesn't appear to be as simple as changing that config endpoint to https since there are multiple files behind the scenes doing things with the xsd's and reference the http endpoint. How can I setup my service / client to force https so that it correctly sets the endpoint?
我的 WCF 服务应用程序通过 http 和 https 工作,但是,当我在客户端中向其添加服务引用(带有 https url)时,Visual Studio 2010 将配置文件中的端点设置为 http。它似乎不像将该配置端点更改为 https 那样简单,因为在幕后有多个文件在使用 xsd 并引用 http 端点。如何设置我的服务/客户端以强制使用 https 以便正确设置端点?
When I try to manually change the endpoint in the config file and set security mode to "Transport" I get this error:
当我尝试手动更改配置文件中的端点并将安全模式设置为“传输”时,出现此错误:
Exception Message: There was no endpoint listening at https://myservice/AvailabilityService.svcthat could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
异常消息:在https://myservice/AvailabilityService.svc 上没有可以接受消息的端点侦听 。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。
I can, however, see that endpoint in IE, and am debugging locally. After I add my service reference with https and search the solution for its http equivolent, it finds a wsdl file referencing http, a configuration.svcinfo, and a configuration91.svcinfo that utilizes the http url instead of https
但是,我可以在 IE 中看到该端点,并且正在本地调试。在我使用 https 添加我的服务引用并搜索其 http 等效项的解决方案后,它会找到一个 wsdl 文件引用 http、一个 configuration.svcinfo 和一个使用 http url 而不是 https 的 configuration91.svcinfo
Here's my server side config:
这是我的服务器端配置:
<?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>
.. And the client side config:
.. 和客户端配置:
<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>
Perhaps I'm better off manually consuming the services in code?
也许我最好手动使用代码中的服务?
回答by Nick Nieslanik
You need to change your binding to use transport security to use HTTPS
您需要更改绑定以使用传输安全性以使用 HTTPS
Your server side binding should be configured for https as well as client:
您的服务器端绑定应该为 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>

