WCF - 远程服务器返回意外响应:(400)错误请求

时间:2011-02-15 07:58:32

标签: wcf

我在将byte []传递给WCF时遇到此错误。有人可以解决这个错误吗?

服务配置(web.config)

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
    </system.web>
    <system.serviceModel>
        <bindings>
   <basicHttpBinding>
    <binding name="NewBinding0" maxBufferSize="2097151" maxBufferPoolSize="2097151"
     maxReceivedMessageSize="2097151" messageEncoding="Mtom"
     transferMode="Streamed">
     <readerQuotas maxDepth="2097151" maxStringContentLength="2097151"
      maxArrayLength="2097151" maxBytesPerRead="2097151" maxNameTableCharCount="2097151" />
    </binding>
   </basicHttpBinding>
   <mexHttpBinding>
    <binding name="higherMessageSize_MEX" />
   </mexHttpBinding>
  </bindings>
  <client>
   <endpoint binding="basicHttpBinding" bindingConfiguration="NewBinding0"
    contract="LService.IService">
    <identity>
     <dns value="localhost" />
    </identity>
   </endpoint>
   <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="higherMessageSize_MEX"
    contract="IMetadataExchange" />
  </client>
  <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- 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>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>

WPF应用程序(app.config)上的配置

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2097151" maxBufferPoolSize="2097151" maxReceivedMessageSize="2097151"
                    messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="2097151" maxStringContentLength="2097151"
                        maxArrayLength="2097151" maxBytesPerRead="2097151" maxNameTableCharCount="2097151" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:5980/LService/Service.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
                contract="LService.IService" name="BasicHttpBinding_IService" />
        </client>
    </system.serviceModel>
</configuration>

1 个答案:

答案 0 :(得分:2)

在不知道您的服务合同和所需的所有细节的情况下 - 我只能推测。

让我感到震惊的是,您的服务器端配置不包含<service>的任何配置。

规则如下:

    服务器端,您的配置中需要一个<services>标记,其中包含任意数量的<service>标记,用于定义该服务器上的每个服务。每个<service>代码都可以包含任意数量的<endpoint>代码,用于定义一个或多个服务端点

    客户端上的
  • ,您有一个或多个<client>条目,每个条目包含一个<endpoint>,用于定义客户端连接到的服务地址< / p>

所以你的服务器端配置应该是这样的:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
          <binding name="NewBinding0" ....... />
      </basicHttpBinding>
      .....
   </bindings>
   <services>
       <service name="YourNamespace.YourService"
                behaviorConfiguration="Default" >
           <endpoint name="BasicEndpoint"
               address="http://localhost:5757/Services"
               binding="basicHttpBinding"
               bindingConfiguration="NewBinding0"
               contract="YourNamespace.IYourServiceContract" />
       </service>
   </services>
   <behaviors>
      <serviceBehaviors>
         <behavior name="Default">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
         </behavior>
      </serviceBehaviors>
   </behaviors>
   ......
</system.serviceModel>

您的客户端配置似乎没问题 - 当然,您必须将服务所在的服务器地址放在address=属性中 - 通常不是localhost