브라우저에서 WCF 메서드 호출이 400 개의 잘못된 요청을 반환합니다.

Dev

Visual Studio 2008에서 C #과 함께 ASP.NET 3.5를 사용하고 있습니다. 저는 WCF에 순진합니다. 샘플 wcf 응용 프로그램을 만들고 Visual Studio의 asp.net 개발 서버에서 실행했습니다. 응용 프로그램을 만들고 400 개의 잘못된 요청을받는 동안 자동 생성 된 GetData () 메서드를 호출하고 있습니다. 많이 시도했지만 결과가 답답합니다.

내 인터페이스 IService1.cs 는 다음과 같습니다.

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

namespace WcfService1
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebInvoke(RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,Method="GET",UriTemplate="/getdata/{}")]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}

Class Service1.svc.cs 파일은 다음과 같습니다.

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

namespace WcfService1
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}

그리고 web.config는 다음과 같습니다.

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>
    <configSections>
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
                    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                    <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                </sectionGroup>
            </sectionGroup>
        </sectionGroup>
    </configSections>
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
        <compilation debug="true">
            <assemblies>
                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </assemblies>
        </compilation>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <authentication mode="None"/>
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
        <pages>
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </controls>
        </pages>
        <httpHandlers>
            <remove verb="*" path="*.asmx"/>
            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
        </httpHandlers>
        <httpModules>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </httpModules>
    </system.web>
    <system.codedom>
        <compilers>
            <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                <providerOption name="CompilerVersion" value="v3.5"/>
                <providerOption name="WarnAsError" value="false"/>
            </compiler>
        </compilers>
    </system.codedom>
    <system.web.extensions>
        <scripting>
            <webServices>
                <!--
              Uncomment this section to enable the authentication service. Include 
              requireSSL="true" if appropriate.

          <authenticationService enabled="true" requireSSL = "true|false"/>
          -->
                <!--
              Uncomment these lines to enable the profile service, and to choose the 
              profile properties that can be retrieved and modified in ASP.NET AJAX 
              applications.

          <profileService enabled="true"
                          readAccessProperties="propertyname1,propertyname2"
                          writeAccessProperties="propertyname1,propertyname2" />
          -->
                <!--
              Uncomment this section to enable the role service.

          <roleService enabled="true"/>
          -->
            </webServices>
            <!--
        <scriptResourceHandler enableCompression="true" enableCaching="true" />
        -->
        </scripting>
    </system.web.extensions>
    <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules>
            <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </modules>
        <handlers>
            <remove name="WebServiceHandlerFactory-Integrated"/>
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </handlers>
    </system.webServer>
    <system.serviceModel>
        <services>
            <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
                <!-- Service Endpoints -->
                <endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1">
                    <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="WcfService1.Service1Behavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="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>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

URL은 다음과 같습니다.

http://localhost:51671/Service1.svc/getdata/1

누구든지 도울 수 있습니까?

마이크 굿윈

4 가지 잘못된 점이 있습니다.

첫째, 당신이 사용되어야한다 webHttpBinding대신 wsHttpBinding. wsHttpBindingREST 서비스가 아닌 SOAP 서비스 전용입니다.

둘째, 엔드 포인트 동작을 추가해야합니다.

따라서 엔드 포인트는 다음과 같습니다.

<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webBehavior">

그리고 행동 섹션에서 당신은

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

셋째, URI 템플릿은

UriTemplate="/getdata/{value}"

보다는

UriTemplate="/getdata/{}"

그리고 마지막으로, 당신은 URI 템플릿에서 사용하는 매개 변수 유형이어야합니다 string그래서,

string GetData(string value);

보다는

string GetData(int value);

서비스 작업 내에서 문자열 값을 올바른 유형으로 구문 분석해야합니다.

전반적으로 WCF REST보다는 ASP.Net WebAPI를 사용하여 REST를 수행 하는 것이 훨씬 쉽습니다. 3.5 대신 .Net 4로 이동할 수 있다면 훨씬 더 빠르게 진행할 수 있고 적절하게 지원되는 플랫폼으로 작업 할 수 있습니다.

또한 개발을 위해서는

<serviceDebug includeExceptionDetailInFaults="true"/>

따라서 무엇이 잘못되었는지에 대한 자세한 정보를 얻을 수 있습니다. false그러나 프로덕션 위해 다시 설정하는 것을 잊지 마십시오.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

WCF Post 메서드, 400 잘못된 요청 반환

분류에서Dev

대부분의 API가 프런트 엔드에서 호출되는 동안 400 개의 잘못된 요청 오류를 반환합니다.

분류에서Dev

개체 속성이 잘못된 경우 WCF (400) 잘못된 요청

분류에서Dev

Google 드라이브 API가 PageToken 사용시 400 잘못된 요청을 반환합니다.

분류에서Dev

Undertow Core HTTPS 서버가 400 개의 잘못된 요청을 제공합니다.

분류에서Dev

원격 서버가 예기치 않은 응답을 반환했습니다. (400) 잘못된 요청 WCF REST

분류에서Dev

API 패치 메서드에서 잘못된 요청 400 반환

분류에서Dev

C # WCF "System.Net.WebException : 원격 서버에서 오류를 반환했습니다 : (400) 잘못된 요청."

분류에서Dev

Amazon s3a가 Spark-redshift 라이브러리와 함께 400 개의 잘못된 요청을 반환합니다.

분류에서Dev

werkzeug.exceptions.BadRequestKeyError : 400 잘못된 요청 : 브라우저 (또는 프록시)가이 서버가 이해할 수없는 요청을 보냈습니다. KeyError : 'id'

분류에서Dev

BadRequestKeyError : 400 잘못된 요청 : 브라우저 (또는 프록시)가이 서버가 이해할 수없는 요청을 보냈습니다. KeyError : '검색'

분류에서Dev

Google Cloud Datastore 요청이 브라우저에서 오류 400을 반환합니다.

분류에서Dev

Laravel 6 여권이 잘못된 자격 증명에 대해 400 잘못된 요청을 반환합니다.

분류에서Dev

Postman에서 Rest API를 호출 할 수 있으며 Java에서 400 개의 잘못된 요청이 표시됨

분류에서Dev

curl은 따옴표없이 400 개의 잘못된 요청을 반환합니다.

분류에서Dev

ALM Rest API : 사이트 세션이 '원격 서버에서 오류를 반환했습니다 : (400) 잘못된 요청'을 반환합니다.

분류에서Dev

WCF 서비스가 잘못된 JSON 출력을 반환합니다.

분류에서Dev

Scrapy가 브라우저 요청과 동일한 요청에서 400 잘못된 요청을 받고 있습니다.

분류에서Dev

오류 400-> wcf 클라이언트 측의 잘못된 요청

분류에서Dev

WCF IIS 서비스 파일 스트리밍 원격 서버에서 예기치 않은 응답 (400) 잘못된 요청을 반환했습니다.

분류에서Dev

HTTP GET이 400 개의 잘못된 요청을 제공합니다 (telnet, arduino).

분류에서Dev

IdentityServer3 ResourceOwner Angular 요청이 400 잘못된 요청을 반환합니다.

분류에서Dev

Docusign 업로드 API 호출이 원격 서버에서 오류를 반환했습니다. (400) 잘못된 요청

분류에서Dev

IAM이 활성화 된 상태에서 AWS Neptune에 연결을 시도 할 때 400 개의 잘못된 요청

분류에서Dev

디렉토리 API 용 gsuite 서비스 계정이 http 400 오류를 반환합니다. 잘못된 요청 / 잘못된 입력

분류에서Dev

LinkedIn API에서 공유가 400 잘못된 요청을 반환하는 이유는 무엇입니까?

분류에서Dev

요청 라이브러리의 잘못된 요청 오류 400

분류에서Dev

두 번째 호출에서 C # WebRequest (400) 잘못된 요청

분류에서Dev

axios.post가 400 React Native의 잘못된 요청을 반환합니다.

Related 관련 기사

  1. 1

    WCF Post 메서드, 400 잘못된 요청 반환

  2. 2

    대부분의 API가 프런트 엔드에서 호출되는 동안 400 개의 잘못된 요청 오류를 반환합니다.

  3. 3

    개체 속성이 잘못된 경우 WCF (400) 잘못된 요청

  4. 4

    Google 드라이브 API가 PageToken 사용시 400 잘못된 요청을 반환합니다.

  5. 5

    Undertow Core HTTPS 서버가 400 개의 잘못된 요청을 제공합니다.

  6. 6

    원격 서버가 예기치 않은 응답을 반환했습니다. (400) 잘못된 요청 WCF REST

  7. 7

    API 패치 메서드에서 잘못된 요청 400 반환

  8. 8

    C # WCF "System.Net.WebException : 원격 서버에서 오류를 반환했습니다 : (400) 잘못된 요청."

  9. 9

    Amazon s3a가 Spark-redshift 라이브러리와 함께 400 개의 잘못된 요청을 반환합니다.

  10. 10

    werkzeug.exceptions.BadRequestKeyError : 400 잘못된 요청 : 브라우저 (또는 프록시)가이 서버가 이해할 수없는 요청을 보냈습니다. KeyError : 'id'

  11. 11

    BadRequestKeyError : 400 잘못된 요청 : 브라우저 (또는 프록시)가이 서버가 이해할 수없는 요청을 보냈습니다. KeyError : '검색'

  12. 12

    Google Cloud Datastore 요청이 브라우저에서 오류 400을 반환합니다.

  13. 13

    Laravel 6 여권이 잘못된 자격 증명에 대해 400 잘못된 요청을 반환합니다.

  14. 14

    Postman에서 Rest API를 호출 할 수 있으며 Java에서 400 개의 잘못된 요청이 표시됨

  15. 15

    curl은 따옴표없이 400 개의 잘못된 요청을 반환합니다.

  16. 16

    ALM Rest API : 사이트 세션이 '원격 서버에서 오류를 반환했습니다 : (400) 잘못된 요청'을 반환합니다.

  17. 17

    WCF 서비스가 잘못된 JSON 출력을 반환합니다.

  18. 18

    Scrapy가 브라우저 요청과 동일한 요청에서 400 잘못된 요청을 받고 있습니다.

  19. 19

    오류 400-> wcf 클라이언트 측의 잘못된 요청

  20. 20

    WCF IIS 서비스 파일 스트리밍 원격 서버에서 예기치 않은 응답 (400) 잘못된 요청을 반환했습니다.

  21. 21

    HTTP GET이 400 개의 잘못된 요청을 제공합니다 (telnet, arduino).

  22. 22

    IdentityServer3 ResourceOwner Angular 요청이 400 잘못된 요청을 반환합니다.

  23. 23

    Docusign 업로드 API 호출이 원격 서버에서 오류를 반환했습니다. (400) 잘못된 요청

  24. 24

    IAM이 활성화 된 상태에서 AWS Neptune에 연결을 시도 할 때 400 개의 잘못된 요청

  25. 25

    디렉토리 API 용 gsuite 서비스 계정이 http 400 오류를 반환합니다. 잘못된 요청 / 잘못된 입력

  26. 26

    LinkedIn API에서 공유가 400 잘못된 요청을 반환하는 이유는 무엇입니까?

  27. 27

    요청 라이브러리의 잘못된 요청 오류 400

  28. 28

    두 번째 호출에서 C # WebRequest (400) 잘못된 요청

  29. 29

    axios.post가 400 React Native의 잘못된 요청을 반환합니다.

뜨겁다태그

보관