无法在HTTPS下访问WCF静态服务(ERR_CONNECTION_RESET)

时间:2018-06-25 07:18:48

标签: c# rest wcf https

我有工作WCF服务(通过win.service)。服务通过HTTP工作,但是当我将配置切换到HTTPS时,我得到ERR_CONNECTION_RESET。

我已经学到了很多有关此问题的信息,但没有解决。

请帮助! :)

我的服务

[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
    public interface IViberService
    {
        [OperationContract]
        [WebInvoke(Method = "POST",
                    ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
                    UriTemplate = "GetData")]
        Task GetData();


        [OperationContract]
        [WebInvoke(Method = "GET",
               ResponseFormat = WebMessageFormat.Json,
               BodyStyle = WebMessageBodyStyle.Wrapped,
               UriTemplate = "Init")]
        Task Init();
    }

    public class ViberService : IViberService
    {   public async Task Init()
        {
           ....
        }

        public async Task GetData()
        {
          ....
        }
    }

我的配置serviceModel

    <system.serviceModel>
        <client>
            <endpoint address="https://......Service.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITelegramService"
                contract="......ITelegramService" name="BasicHttpBinding_ITelegramService" />
        </client>
      <services>
        <!-- This section is optional with the new configuration model  
           introduced in .NET Framework 4. -->

        <service name="Microsoft.ServiceModel.Samples.ViberService"
                 behaviorConfiguration="ViberServiceBehavior" >
          <host>
            <baseAddresses>
              <add baseAddress="https://localhost:8001/ServiceModelSamples/ViberService"/>
            </baseAddresses>
          </host>
          <endpoint address=""
                    binding="webHttpBinding"
   contract="Microsoft.ServiceModel.Samples.IViberService" behaviorConfiguration="webBehavior" bindingConfiguration="WebHttpBindingConfig"/>
          <endpoint address="mex"
                    binding="mexHttpsBinding"
                    contract="IMetadataExchange" />

        </service>
      </services>
      <bindings>
        <basicHttpBinding>
          <binding name="BasicHttpBinding_ITelegramService">
            <security mode="Transport" />
          </binding>
        </basicHttpBinding>
        <webHttpBinding>
          <binding name="WebHttpBindingConfig">
            <security mode="Transport"/>
          </binding>
        </webHttpBinding>
      </bindings>
      <behaviors>
        <endpointBehaviors>
          <behavior name="webBehavior">
            <webHttp  />
          </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
          <behavior name="ViberServiceBehavior">
            <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
    </system.serviceModel>
</configuration>

先谢谢您!

相同的代码在HTPP下可以正常工作

UPD:我使用GetData中上下文中的数据。

string _data = OperationContext.Current.RequestContext.RequestMessage.ToString();

也许是这个问题

0 个答案:

没有答案