lundi 8 octobre 2018

Getting 400 Bad Request when trying to use wcf service from another wcf service

I'm trying to call a WCF service from another WCF service, but when I try to call a specific method I get "System.ServiceModel.ProtocolException: 'The remote server returned an unexpected response: (400) Bad Request.'" . Both services are hosted on IIS. This is the configuration of the service I'm calling:

    <?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" maxRequestLength="2000000"/>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="serviceBehaviour" name="AuthenticationService.WcfService">
        <endpoint address="rest"  name="AuthEndpoint"
                  behaviorConfiguration="webBehaviour" binding="webHttpBinding" bindingConfiguration="webBindingConfig"
          contract="Interfaces.Wcf.IWcfAuthenticationService">   
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/AuthenticationService" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="webBehaviour">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="serviceBehaviour">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding  name="webBindingConfig" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000" >
      <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000"
                    maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
    </binding>
  </webHttpBinding>
</bindings>

<protocolMapping>
    <add binding="webHttpBinding" scheme="http" />
</protocolMapping>    

  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>

    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

In the cilent configuration I have:

<client>
  <endpoint address="http://localhost/AuthenticationService/WcfService.svc/rest"  name="AuthEndpoint"
             behaviorConfiguration="webBehaviour" 
            binding="webHttpBinding"
            bindingConfiguration="webBindingConfig"
            contract="Interfaces.Wcf.IWcfAuthenticationService" />
</client>

I'm creating the service instance with the ChannelFactory class like this:

var channelFactory = new ChannelFactory<IWcfAuthenticationService>("AuthEndpoint");
var service = channelFactory.CreateChannel();




Aucun commentaire:

Enregistrer un commentaire