简体   繁体   中英

IIS: WCF service with https and GET -> HTTP 400 Error

I am trying to create a WCF Service for https binding. The service was working with http before. I changed the binding (with certificate) and now I configure the web.config - but I always get error code "400 - Bad Request".

The web service is called with: https://servername:444/FolderService.svc/FolderExists/1234 https://servername:444/FolderService.svc/Test

This is my service interface:

[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();
}

And this is my 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>

I tried so many different configuration without success. Does anyone have an idea (or a working example)?

Thanks in advance!

You are trying to access your methods in a RESTful manner via a URL. However, what you have wrong in your web.config is that you are using BasicHttpBinding which is for SOAP web services and not RESTful web services.

WebGet and WebInvoke are the necessary attributes to add to your operations as you have already done.

However, the correct binding for the endpoint is WebHttpBinding and the behavior you need to apply to the endpoint is the WebHttpBehavior .

Sample Abbreviated Configuration:

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

<endpointBehaviors> 
    <behavior name="webBehavior"> 
        <webHttp /> 
    </behavior> 
</endpointBehaviors> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM