2011-08-22 123 views
0

我得到了同樣的錯誤:POST方法在WCF REST服務

protected void Button1_Click(object sender, EventArgs e) 
      { 
      BasicHttpBinding binding = new BasicHttpBinding(); 
      binding.ReaderQuotas.MaxStringContentLength = 2000000; 
      binding.MaxBufferSize = 2147483647; 
      binding.MaxReceivedMessageSize = 2147483647; 
      binding.ReaderQuotas.MaxNameTableCharCount = 2147483647; 
      binding.Security.Transport.ClientCredentialTypeHttpClientCredentialType.Windows; 
      binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
      binding.CloseTimeout = new TimeSpan(4, 0, 0); 
      binding.OpenTimeout=new TimeSpan(4, 0, 0); 
      binding.ReceiveTimeout=new TimeSpan(2, 0, 0); 
      binding.SendTimeout = new TimeSpan(5, 0, 0); 
      EndpointAddress endpoint = new EndpointAddress(new Uri("http://localhost:35798/RestServiceImpl.svc")); 
      RestPostService.RestServiceImplClient obj = new RestPostService.RestServiceImplClient(binding, endpoint); 
      RestPostService.EmailDetails obj1 = new RestPostService.EmailDetails(); 
      obj.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; 
      RestPostService.EmailDetails obj2=obj.SendMail(obj1); 
     } 


**web.config** 
<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
     <binding name="webHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"/> 
     </webHttpBinding> 
    </bindings> 
    <services> 
     <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour"> 
     <endpoint address ="http://localhost:35798/RestServiceImpl" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="webHttp"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="webHttp"> 
      <!-- 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="true"/> 
      <dataContractSerializer maxItemsInObjectGraph="6553600"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

我應該爲了使代碼工作取得了哪些變化。
錯誤:The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

請幫助解決問題。

+0

咦? .......... –

+0

請明確你的問題是什麼。這甚至不像C++,它看起來更像c#。 –

回答

0

您在代碼中使用錯誤的WCF綁定。配置XML顯示使用WebHttpBinding的WCF服務。重構你的客戶創造的代碼是這樣的:

WebHttpBinding binding = new WebHttpBinding(); 
// The rest of the configuration 

不知道,如果你要設置的屬性將是有效的這種結合,但是編譯器會知道:)