WCF - HTTPS/HTTP Hosting & Cosuming

本文关键字:amp Cosuming Hosting HTTP HTTPS WCF | 更新日期: 2023-09-27 18:33:48

我遇到了一个奇怪的问题,我在本地计算机上托管了一个WCF服务,我已经在其上启用了SSL,我的服务web.config如下所示;

<system.serviceModel>
<services>
  <service behaviorConfiguration="PostingBehavior" name="IMedTabletHL7Service.Hl7Service">
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="PostingCapable" contract="IMedTabletHL7Service.IHL7Service">
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp defaultBodyStyle="Wrapped" faultExceptionEnabled="true" helpEnabled="true"></webHttp>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="PostingBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Buffered" receiveTimeout="00:30:00">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
  <mexHttpsBinding>
    <binding name="NewBinding0" />
  </mexHttpsBinding>
  <webHttpBinding>
    <binding name="PostingCapable" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Buffered" receiveTimeout="00:30:00">
      <security mode="Transport">
        <transport proxyCredentialType="None" clientCredentialType="None"></transport>
      </security>
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </webHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

我的桌面应用程序.config 文件看起来像这样;

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IHL7Service" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
          maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport proxyCredentialType="None" clientCredentialType="None"></transport>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>    
<client>
  <endpoint address="https://localhost/IMedTabletHL7Service/Hl7Service.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHL7Service"
      contract="HL7Webservice.IHL7Service" name="BasicHttpBinding_IHL7Service" />
</client>

它把我扔在错误之后;

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at https://localhost/IMedTabletHL7Service/Hl7Service.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`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

此外,当我从浏览器访问服务时,它不会给我任何错误。

WCF - HTTPS/HTTP Hosting & Cosuming

一个问题是您的服务和客户端对其端点使用不同的绑定(服务:webHttpBinding,客户端:basicHttpBinding)。