远程服务器返回意外响应:(400) 错误请求。 wcf
The remote server returned an unexpected response: (400) Bad Request. wcf
我有一个使用 wcf 网络服务的网络项目,但它运行不正常。
这里我包含了 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>
当应用程序请求时,它会给我这样的错误 post title
这里我包含了调用此服务的方法。
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]添加到接口的自动生成操作中,以保持服务器和客户端之间绑定的一致性。它位于自动生成的客户端代理 class.
我们通过添加服务引用来使用 WCF 服务,当使用 WebHttpBinding 创建服务时会有所不同。此类服务一般称为Restful式服务,我们在浏览器中输入服务地址即可直接调用。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service
所以如果我们想使用客户端代理来消费服务class,我们需要保持服务端和客户端绑定的一致性,就像WCF SOAP服务一样
如果问题仍然存在,请随时与我联系。
我有一个使用 wcf 网络服务的网络项目,但它运行不正常。
这里我包含了 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>
当应用程序请求时,它会给我这样的错误 post title
这里我包含了调用此服务的方法。
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]添加到接口的自动生成操作中,以保持服务器和客户端之间绑定的一致性。它位于自动生成的客户端代理 class.
我们通过添加服务引用来使用 WCF 服务,当使用 WebHttpBinding 创建服务时会有所不同。此类服务一般称为Restful式服务,我们在浏览器中输入服务地址即可直接调用。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service
所以如果我们想使用客户端代理来消费服务class,我们需要保持服务端和客户端绑定的一致性,就像WCF SOAP服务一样
如果问题仍然存在,请随时与我联系。