WCF 400错误请求(自托管) [英] WCF 400 Bad request (Self hosted)

查看:82
本文介绍了WCF 400错误请求(自托管)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我讨厌发帖问题(希望这个问题出来了)。总是试图在论坛中找到答案。这一次,我很难过。我知道关于这个问题有一百万个问题,但我仍然无法找到答案。



问题:(我是WCF的新手)

我正在尝试从客户端向服务器发送文件。通常的45kb工作,但没有更大,因为400错误的请求弹出并破坏了我的发型。看起来我的设置与其他人使用的设置有点不同,因为我正在进行自托管。结果我没有web.config文件,或者......我应该有吗?无论如何,我用破坏的键盘(键中的头发)破坏了这个代码,试图通过删除和插入来自一百万和两个论坛的东西来弄清楚它有什么问题。我需要第二双眼睛来看看这个并告诉我哪里出错了。任何建议都将不胜感激。



设置:

我在本地运行服务器端和DEV中的客户端机。 C#.net 3.5。

WCF在控制台应用程序中自托管。



服务器app.config:

Hi All.
I hate posting questions (hope this one came out OK). Always trying to find the answers in forums first. This time around I'm stumped. I know there are a million and 2 questions asked about this subject and still I cant find my answer.

The Problem: (I'm new to WCF)
I'm trying to send a file to the server from the client. The usual 45kb works but none bigger as the 400 bad request pops up and ruins my hair style. It looks like my setup is a bit different from what other people are using as I am doing self hosting. As a result I do not have a web.config file, or... should I have one? Anyway I have mutilated this code with a broken keyboard (hair in the keys) trying to figure out what's wrong with it by deleting and plugging in stuffs from a million and 2 forums. I need a second pair of eyes to look at this and tell me where I'm going wrong. Any and every suggestion will be greatly appreciated.

The setup:
I am running a server side and a client in DEV on the local machine. C#.net 3.5.
WCF is self hosted in console app.

Server app.config:

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

  <system.web>
    <compilation debug="true" />
    <httpRuntime maxRequestLength="67108864"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="WCFRemote.Service1Behavior" name="WCFRemote.Interface">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="WCFRemote.IInterface">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/WCFRemote/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
          <binding name="basicHttpBinding"

              maxReceivedMessageSize="67108864"

              maxBufferSize="67108864" transferMode="Streamed" >

          <readerQuotas maxDepth="67108864" maxStringContentLength="67108864"

               maxArrayLength="67108864" maxBytesPerRead="67108864"

               maxNameTableCharCount="67108864"/>
        </binding>
       </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WCFRemote.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>

< br $>


客户端app.config:



Client app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IInterface" closeTimeout="04:01:00"

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

                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferSize="67108864" maxBufferPoolSize="67108864" maxReceivedMessageSize="67108864"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"

                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="67108864" maxArrayLength="67108864"

                        maxBytesPerRead="67108864" maxNameTableCharCount="67108864" />
                  <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"

                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://jay-vm7dev:8080/service/basic" binding="basicHttpBinding"

                bindingConfiguration="BasicHttpBinding_IInterface" contract="ServiceReference1.IInterface"

                name="BasicHttpBinding_IInterface"/>
        </client>
    </system.serviceModel>
</configuration>





I would have ask my colleges to have a look but since I’m the only developer in my company... Help...



Thanx in Advance from the guy looking like a cancer patient. KCCO!



I would have ask my colleges to have a look but since I'm the only developer in my company... Help...

Thanx in Advance from the guy looking like a cancer patient. KCCO!

推荐答案

I googled about it &发现了这个。 please check if this helps you.







You are very close to the solution, but you are mixing the bindings. Your service is using basicHttpBinding, but you have set the size limits on webHttpBinding.



Therefore: In your web.config for the service, replace webHttpBinding with basicHttpBinding and this will work, like this:

I googled about it & found this. please check if this helps you.



You are very close to the solution, but you are mixing the bindings. Your service is using basicHttpBinding, but you have set the size limits on webHttpBinding.

Therefore: In your web.config for the service, replace webHttpBinding with basicHttpBinding and this will work, like this:
<basichttpbinding>
   <binding maxbuffersize="64000000" maxreceivedmessagesize="64000000" maxbufferpoolsize="64000000">
     <readerquotas maxdepth="64000000" maxstringcontentlength="64000000" maxarraylength="64000000" maxbytesperread="64000000" />
     <security mode="None" />
   </binding>
 </basichttpbinding>





Increase the timeout time & buffer size at both ends. I have seen 9 to 10 digits size.



Links might help you



http://forums.asp.net/t/1299246.aspx/1[^]



WCF Service returns (400) Bad Request[^]



http://stackoverflow.com/a/784684[^]


这篇关于WCF 400错误请求(自托管)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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