VS2010 WCF 远程服务器返回了意外响应: (400) Bad Request等问题解决方案

1. wcf相关项目名称Service1.svcIDataChangeTest.csDataChangeTest.cs(下面的专业名称可能不太准确)。

Service1.svc宿主,里面只关联接口的空间

IdataChangeTest.cs里边是接口,如下:

……

      /// <summary>
      /// 通过特定表的特定字段取得Datatable
      /// </summary>
      /// <param name="tableName">表名</param>
      /// <param name="fieldname">字段名</param>
      /// <param name="fieldval">对应的值</param>
      /// <param name="accWord">验证编码</param>
      /// <returns></returns>
    [OperationContract]
    DataTable GetTableDataByField(string tableName, string fieldname, string fieldval, string accWord);

……    

DataChangeTest.cs为实际的方法,如下:

……

   

 

2. 下面是wcfconfig设置:

<configuration>
       <system.serviceModel>
               <bindings>
                       <wsHttpBinding>
<!-- 2147483647最大字节数,这个是int32的最大字节数,大小是2047M,肯定能适合正常的数据传输。估计不用全部设置成这么大都够用。-->
                               <binding name="NewBinding0" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
                                       <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                               </binding>
                       </wsHttpBinding>
               </bindings>
               <behaviors>
                       <serviceBehaviors>
                               <behavior name="metadataBehavior">
                                       <serviceMetadata httpGetEnabled="true"/>
         <serviceDebug includeExceptionDetailInFaults="false"/>
                               </behavior>
                       </serviceBehaviors>
               </behaviors>
<!—metadataBehavior对应的是“<behavior name="metadataBehavior">”的name,名称无所谓,只要对应就好。Services.DataChangeTest是调用方法DataChangeTest.cs窗体对应的空间名称和窗体类名称;Contracts.IdataChangeTest是调用接口IdataChangeTest.cs窗体对应的空间名称和窗体类名称;NewBinding0对应上面“<binding name="”的name-->
               <services>
                       <service behaviorConfiguration="metadataBehavior" name="Services.DataChangeTest">
                               <endpoint binding="wsHttpBinding" bindingConfiguration="NewBinding0" contract="Contracts.IDataChangeTest"/>
                       </service>
<!—下面两处红色的部分会影响发布之后scf的调用,如果没有,发布之后无法引用。-->
               </services>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
       </system.serviceModel>
 <system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>
 <system.web>
               <compilation debug="true"/>
 </system.web>
</configuration>

 

3.下面是app.config里面的设置,这个基本上是引用Service Reference时自动产生的,我只是把对应的size改的大了些。

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.serviceModel>

        <bindings>

            <wsHttpBinding>

                <binding name="WSHttpBinding_IDataChangeTest" closeTimeout="00:01:00"

                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"

                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"

                    allowCookies="false">

                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647"

                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

                    <reliableSession ordered="true" inactivityTimeout="00:10:00"

                        enabled="false" />

                    <security mode="Message">

                        <transport clientCredentialType="Windows" proxyCredentialType="None"

                            realm="" />

                        <message clientCredentialType="Windows" negotiateServiceCredential="true" />

                    </security>

                </binding>

            </wsHttpBinding>

        </bindings>

<!—http://192.168.254.64:82/Service1.svc是发布之后的地址;

WSHttpBinding_IDataChangeTest这个是上面bingname,这个可能是由ServiceReference1.IdataChangeTest的来的,估计可以随便写,个人猜测  

ServiceReference1.IdataChangeTest这个是对应引用的ServiceReference1,双击他,左面会显示出来,如下面的图片-->

        <client>

            <endpoint address="http://192.168.254.65:82/Service1.svc" binding="wsHttpBinding"

                bindingConfiguration="WSHttpBinding_IDataChangeTest" contract="ServiceReference1.IDataChangeTest"

                name="WSHttpBinding_IDataChangeTest">

                <identity>

                    <servicePrincipalName value="host/Hqyr-PC" />

                </identity>

            </endpoint>

        </client>

    </system.serviceModel>

</configuration>

 


 
  上面只是解决的具体方法,相信我说的已经很详细了。之前查过很长时间,一直未找到解决的方案。现在解决,我在想不是之前查到的那些文章没有说明白,应该是自己没有静下心来好好的看吧。很多时候遇到问题,我们总是在想:找到个一下子能解决的方法,却忽略了很多细节。也许我更关注的是结果,而不是过程。虽然受时间的压迫这个因素会让我们倾向于这样想!我想细节能影响一件事情的成败,更决定了一个人的层次。
  在努力一点,细心一点,你会更成功!跟自己说,跟像我一样 急功近利 的人说。
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值