Удаленный сервер вернул неожиданный ответ: (400) неверный запрос. Отправить список в службу wcf - PullRequest
0 голосов
/ 28 мая 2020

У меня есть служба wcf. мы хотим отправить List методу в сервисе. ошибка Удаленный сервер возвратил неожиданный ответ: (400) Появился неверный запрос.

при использовании PostMan все в порядке.

вот служба в IService:

OperationContract]
WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
<bool, Exception, bool> InsertSarfaslList(List<ProjectsSarfaslWCFModel> lst);

Hear is service in Service:

Tuple<bool, Exception, bool> InsertSarfaslList(List<ProjectsSarfaslWCFModel> lst)
{
      new Tuple<bool, Exception, bool>(true, null, true);
}

вот клиент для вызова сервиса

List<ProjectsSarfaslWCFModel> lst = new List<ProjectsSarfaslWCFModel>();

lst.Add(new ProjectsSarfaslWCFModel() { ProjectID = Guid.Empty, ProjectName = txtProjectName.Text, SarfaslCode = txtSarfaslCode.Text, SarfaslName = txtSarfaslName.Text });

lst.Add(new ProjectsSarfaslWCFModel() { ProjectID = Guid.Empty, ProjectName = txtProjectName.Text, SarfaslCode = txtSarfaslCode2.Text, SarfaslName = txtSarfaslName2.Text });

bsflasherService.IbsServiceClient service = new bsflasherService.IbsServiceClient("WebHttpBinding_IbsService");

var ansInsert = service.InsertSarfaslList(lst.ToArray());

вот конфигурация клиента

  <system.serviceModel>
    <client>
      <endpoint address="http://localhost:9090/bsService/?wsdl" binding="webHttpBinding" bindingConfiguration="Web" behaviorConfiguration="webhttp" contract="bsflasherService.IbsService" name="WebHttpBinding_IbsService" />

    </client>

    <bindings>
      <basicHttpBinding>
        <binding name="WebHttpBinding_IbsService" allowCookies="true"
                 maxReceivedMessageSize="20000000"
                 maxBufferSize="20000000"
                 maxBufferPoolSize="20000000">
          <readerQuotas maxDepth="32"
                         maxArrayLength="200000000"
                         maxStringContentLength="200000000"/>
        </binding>

        <binding name="BasicHttpBinding_IbsService" allowCookies="true"
          maxBufferPoolSize="20000000" maxBufferSize="20000000" maxReceivedMessageSize="20000000">
          <readerQuotas maxDepth="32" maxStringContentLength="200000000"
            maxArrayLength="200000000" />
        </binding>
      </basicHttpBinding>

      <webHttpBinding>
        <binding name="Web" maxReceivedMessageSize="250000000" maxBufferSize="250000000" maxBufferPoolSize="250000000" closeTimeout="00:10:00" openTimeout="00:10:00"
    receiveTimeout="00:10:00" sendTimeout="00:10:00">

          <readerQuotas maxDepth="250000000" maxStringContentLength="250000000" maxArrayLength="250000000" maxBytesPerRead="250000000"
          maxNameTableCharCount="250000000"/>
          <security mode="None" />

        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ServiceBehaviour">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>

        <behavior name="webhttp">
          <webHttp defaultBodyStyle="WrappedRequest" />
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>

      </endpointBehaviors>

    </behaviors>
  </system.serviceModel>

конфигурация сервера:

<system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages = "false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="false"/>
    </diagnostics>
    <services>
 <service behaviorConfiguration="bsServiceBehavior" name="bsService">
        <endpoint address = "http://localhost:9090/bsService/" binding="webHttpBinding" bindingConfiguration="Web" contract="bsflasherService.IbsService" behaviorConfiguration="EndpBehavior"/>

        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:9090/bsService/" />
          </baseAddresses>
        </host>
      </service>
</services><bindings>
      <webHttpBinding>

        <binding name="Web" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" closeTimeout="00:10:00" openTimeout="00:10:00"
     receiveTimeout="00:10:00" sendTimeout="00:10:00">

          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647"/>
          <security mode="None" />
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EndpBehavior">
          <webHttp/>
        </behavior>

        <behavior name="EndSaleBehavior">
        </behavior>

      </endpointBehaviors>

      <serviceBehaviors>

        <behavior name="bsServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
...