【问题标题】:IIS: WCF service with https and GET -> HTTP 400 ErrorIIS:带有 https 和 GET 的 WCF 服务 -> HTTP 400 错误
【发布时间】:2023-03-23 08:22:01
【问题描述】:

我正在尝试为 https 绑定创建 WCF 服务。该服务之前使用http。我更改了绑定(使用证书),现在我配置了 web.config - 但我总是收到错误代码“400 - 错误请求”。

使用以下方式调用 Web 服务: https://servername:444/FolderService.svc/FolderExists/1234 https://servername:444/FolderService.svc/Test

这是我的服务接口:

[ServiceContract]
public interface IFolderService
{
    [OperationContract]
    [WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/FolderExists/{accountnumber}")]
    bool FolderExists(string accountnumber);

    [OperationContract]
    [WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Test")]
    string Test();
}

这是我的 web.config:

<?xml version="1.0"?>
<configuration>

  <system.serviceModel>
    <services>
      <service name="myService.FolderService">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="secureHttpBinding"
                  contract="myService.IFolderService"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpsGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

我尝试了很多不同的配置,但都没有成功。有没有人有想法(或工作示例)?

提前致谢!

【问题讨论】:

    标签: c# wcf iis https get


    【解决方案1】:

    您正在尝试通过 URL 以 RESTful 方式访问您的方法。但是,您在 web.config 中的错误在于您使用的是BasicHttpBinding,它用于 SOAP Web 服务而不是 RESTful Web 服务。

    WebGetWebInvoke 是添加到您的操作中的必要属性,就像您已经完成的那样。

    但是,端点的正确绑定是WebHttpBinding,而您需要应用到端点的行为是WebHttpBehavior

    示例缩写配置:

    <service> 
        <endpoint behaviorConfiguration="webBehavior" 
                  binding="webHttpBinding" 
                  contract="myService.IFolderService" 
                  bindingConfiguration="secureHttpBinding" /> 
    </service> 
    
    <endpointBehaviors> 
        <behavior name="webBehavior"> 
            <webHttp /> 
        </behavior> 
    </endpointBehaviors> 
    

    【讨论】:

      猜你喜欢
      • 2014-09-11
      • 1970-01-01
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多