2011-02-15 125 views
0

我在將byte []傳遞給WCF時出現此錯誤。有人可以解決這個錯誤?WCF - 遠程服務器返回了意外的響應:(400)錯誤的請求

配置在提供服務(web.config中)在WPF應用程序(app.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> 

配置

<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> 
+0

如果您發佈代碼,XML或數據樣本, **請**在文本編輯器中突出顯示這些行,然後單擊編輯器工具欄上的「代碼示例」按鈕({}),以便對其進行精確格式化和語法突出顯示! – 2011-02-15 08:03:28

回答

2

不知道您的服務合同和所需的所有細節 - 我只能猜測。

令我震驚的是,您的服務器端配置不包含<service>的任何配置。

的規則是這樣的:

  • 服務器端,你需要一個<services>標籤在你的配置,其中包含任意數量的<service>標籤,它定義了服務器上的每個服務。每個<service>標籤又可以包含任意數量的<endpoint>標籤來定義客戶上的一個或多個服務端點

  • ,您有一個或多個<client>條目,每個條目中都包含一個<endpoint>,它定義了服務地址您的客戶端連接到

所以,你的服務器端的配置應該是這個樣子:

<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

相關問題