远程服务器返回了意外的响应:(400)错误的请求。 wcf [英] The remote server returned an unexpected response: (400) Bad Request. wcf

查看:110
本文介绍了远程服务器返回了意外的响应:(400)错误的请求。 wcf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用wcf Web服务的Web项目,但运行不正常。

i have one web project that uses wcf web services and it's not works fine.

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

here i include web config file for more understand :

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

当应用程序请求时,它给我这样的帖子标题错误

when application requests then it's gives me error like this post title

此处我包括调用此服务的方法。

here i include my method to call this services.

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);
            }
        }

我不明白这里出了什么问题,请帮帮我..

i dont understand what's wrong here please help me up guys..

推荐答案

我们应该将 [WebGet] / [WebInvoke] 添加到自动接口生成的操作,以便保持服务器和客户端之间绑定的一致性。它位于自动生成的客户端代理类中。

我们通过添加服务引用来使用WCF服务,使用WebHttpBinding创建服务时会有所不同。这种类型的服务通常称为Restful风格的服务,我们可以通过在浏览器中输入服务地址直接调用它。

https://docs.microsoft.com/zh-cn/ dotnet / framework / wcf / feature-details / how-to-create-a-basic-wcf-web-http-service

因此,如果我们想通过使用客户端来使用该服务代理类,我们需要保持服务器和客户端之间绑定的一致性,就像WCF SOAP服务一样。

如果问题仍然存在,请随时与我联系。

We are supposed to add [WebGet]/[WebInvoke] to the auto-generated operation of the interface so that it maintains consistency of binding between server and client. It located in the auto-generated client proxy class.
We consume the WCF service by adding service reference, there is a difference when the service is created with WebHttpBinding. This type of service is typically called Restful style service, we could call it directly by inputting the service address in the browser.
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service
So if we want to consume the service by using a client proxy class, we need to maintain the consistency of binding between the server and client, just like the WCF SOAP service.
Feel free to contact me if the problem still exists.

这篇关于远程服务器返回了意外的响应:(400)错误的请求。 wcf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆