尝试从另一个WCF服务使用WCF服务时收到400错误请求

时间:2018-10-08 07:27:21

标签: c# .net wcf web service

我正在尝试从另一个WCF服务中调用WCF服务,但是当我尝试调用特定方法时,我得到了“ System.ServiceModel.ProtocolException:'远程服务器返回了意外的响应:(400)错误的请求。 '”。两种服务都托管在IIS上。这是我正在调用的服务的配置:

    <?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>

在当前配置中,我有:

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

我正在使用ChannelFactory类创建服务实例,如下所示:

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

0 个答案:

没有答案