HTTP 400 Bad Request для метода GET-запрос для WCFService - PullRequest
0 голосов
/ 22 ноября 2018

Я использую Fiddler для проверки своего веб-сервиса.Он подключается к базе данных сервера SQL (которая подключена и работает). Get работает на локальном хосте и через IIS Express в VS 2017. В IIS сервер работает, за исключением запроса GET через fiddler.Пожалуйста, дайте мне знать, если вам нужно увидеть мой Service1.svc файл (слишком много кода не хватает текстовой ошибки) Я попробовал все остальные ответы

Fiddler Example

Fiddler Example

web.config

<appSettings>
  <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
  <compilation debug="true" targetFramework="4.6.1" />
  <httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>

      <!--<behavior>
         To avoid disclosing metadata information, set the values below to false before deployment
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
         To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior> -->
  <bindings>
    <webHttpBinding>
      <binding name="restLargeBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed">
        <readerQuotas maxStringContentLength="2147483647"/>
      </binding>
    </webHttpBinding>
  </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="myWebEndPointBehaviour">
        <webHttp automaticFormatSelectionEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" helpEnabled="true"/>
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      </behavior>
    </endpointBehaviors> 

    <serviceBehaviors>
      <behavior name="myServiceBehaviour">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <services>
    <service name="TestWcfService.Service1" behaviorConfiguration="myServiceBehaviour">
      <endpoint address="" contract="TestWcfService.IService1" binding="webHttpBinding" bindingConfiguration="restLargeBinding" behaviorConfiguration="myWebEndPointBehaviour"></endpoint>
      <endpoint address="mex" contract="TestWcfService.IService1" binding="mexHttpBinding" />
    </service>
  </services>

  <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
  </protocolMapping>    
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
      To browse web app root directory during debugging, set the value below to true.
      Set to false before deployment to avoid disclosing web app folder information.
    -->
  <directoryBrowse enabled="true"/>
</system.webServer>

IService1.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace TestWcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {

        // TODO: Add your service opperations here

        // Get Method
        [OperationContract]
        [WebGet(UriTemplate = "GetUserName")]
        List<UserName> GetUserName();

        // Post Method
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "AddUser", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        int AddUser(string user);

    }

    [DataContract]
    public class UserName
    {
        string user;

        [DataMember]
        public string User
        {
            get { return user; }
            set { user = value; }
        }
    }
}

1 Ответ

0 голосов
/ 22 ноября 2018

Мне нужно было найти правильное сообщение об исключении.Есть несколько разных способов сделать это, но самым простым в этом случае было использование fiddler (потому что ошибка была вызвана при его использовании).Все, что мне нужно было сделать, это вставить Uri, который я использовал для запроса GET, и вставить его в браузер.Это дало мне исключение и детали трассировки.Затем я использовал сообщение об исключении Login failed for user 'IIS APPPOOL\WCFService для поиска ответа.Принятый ответ на этот вопрос Ошибка входа для пользователя 'IIS APPPOOL \ ASP.NET v4.0' - это решение (имя входа может незначительно отличаться в зависимости от точного кода ошибки и службы, которую вы используете)

Надеюсь, это поможет кому-то еще.

...