簡體   English   中英

遠程服務器返回了意外的響應:(400)錯誤的請求。 WCF

[英]The remote server returned an unexpected response: (400) Bad Request. wcf

我有一個使用WCF Web服務的Web項目,但效果不佳。

在這里,我包含了Web配置文件,以供更多了解:

    <?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="FolderPath" value="excel/"/>
    <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;"/>
  </appSettings>
      <system.Web>
        <httpRuntime targetFramework="4.6.1" />
      </system.Web>
  <system.web>
    <httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
    </httpHandlers>
    <compilation debug="true" targetFramework="4.6.1">
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </buildProviders>
      <assemblies>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      </assemblies>
    </compilation>
    <httpRuntime maxRequestLength="2147483647" executionTimeout="99999999"/>

    <pages>
      <controls>
        <add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
        <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </controls>
    </pages>
  </system.web>
  <system.webServer>
    <defaultDocument>
      <files>
        <clear/>
        <add value="Login.aspx"/>
      </files>
    </defaultDocument>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <remove name="ChartImageHandler"/>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </handlers>
  </system.webServer>
  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="LargeWeb" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="infinite">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="32" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://staffapi.vayak.net/staff_care_wcf_ws/RestServiceImpl.svc" binding="webHttpBinding" bindingConfiguration="LargeWeb" contract="SC_WCF.IRestServiceImpl" name="" behaviorConfiguration="web"/>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
</configuration>

當應用程序請求時,它給了我這樣的帖子標題錯誤

在這里,我包括調用此服務的方法。

public void Fill_Combo(Page pg, DropDownList ddl, string combo_type, int Active_Only = 1, int Help_ID = 0, int All_Req = 1, string All_Str = "All", string Filter_Str = "")
        {
            cls_combo obj = new cls_combo();
            cls_combo[] obj_li = null;

            try
            {
                cls_combo_in obj_in = new cls_combo_in();
                obj_in.db_name = CommonLogic.GetSessionValue("sdb_name");
                obj_in.Combo_Type = combo_type;
                obj_in.Active_Only = Active_Only;
                obj_in.help_id = Help_ID;
                obj_in.Add_Str_Req = All_Req;
                obj_in.Add_Str = All_Str;
                obj_in.Staff_ID = Convert.ToInt32(CommonLogic.GetSessionValue("staff_id"));
                obj_in.Is_Admin = Convert.ToBoolean(CommonLogic.GetSessionValue("is_admin")) == true ? 1 : 0;

                obj_li = obj_main.get_combo(obj_in);



                if (obj_li.Length > 0)
                {
                    ddl.DataSource = obj_li;
                    ddl.DataTextField = "Value";
                    ddl.DataValueField = "ID";
                    ddl.DataBind();
                }
                else
                {
                    CommonLogic.SetSessionValue("combo_type", combo_type);
                    pg.Response.Redirect("alert.aspx");
                }

            }
            catch (Exception ex)
            {
                CommonLogic.SendMailOnError(ex);
            }
        }

我不明白這是怎么回事,請幫幫我。

我們應該將[WebGet] / [WebInvoke]添加到該接口的自動生成的操作中,以便保持服務器和客戶端之間綁定的一致性。 它位於自動生成的客戶端代理類中。
我們通過添加服務引用來使用WCF服務,使用WebHttpBinding創建服務時會有所不同。 這類服務通常稱為Restful樣式服務,我們可以通過在瀏覽器中輸入服務地址直接調用它。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service
因此,如果我們想通過使用客戶端代理類來使用該服務,則需要像WCF SOAP服務一樣保持服務器和客戶端之間綁定的一致性。
如果問題仍然存在,請隨時與我聯系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM