2011-05-09 92 views
1

在我的項目中,提供了一個wcf restful服務,允許用戶將照片上傳到Web服務。在將transferMode更改爲「Streamed」後,無法加載wcf寧靜的幫助頁面

更改配置設置後允許大文件上傳。 (添加綁定配置,即「TransferMode」,「BufferSize」等) 所有操作合約都按預期工作。

但是,端點的服務幫助頁面停止工作。

幫助頁面回來,我一旦取消對我的終點

我怎樣才能解決了這個綁定配置設置?這裏沒有我錯過了

謝謝大家

<bindings> 
      <webHttpBinding> 
       <!-- buffer: 64KB; max size: 64MB --> 
       <binding name="StreamedBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
         receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed" 
         maxBufferPoolSize="67108864" maxBufferSize="65536" maxReceivedMessageSize="67108864"> 
       </binding> 
      </webHttpBinding> 
</bindings> 

<service name="WCFRestFul.ApiRestful"> 
     <endpoint address="" binding="webHttpBinding" 
        bindingConfiguration="StreamedBinding" bindingName="StreamedBinding" 
        contract="WCFRestFul.IApiRestful" behaviorConfiguration="web" /> 
</service> 

更新: 我認爲這是轉方式的,只是因爲沒有,但也許一些其他的設置也是如此。 當我在上面的代碼中刪除「bindingConfiguration」時,服務幫助頁面會回來。 我有2個端點。另一個端點沒有「bindingConfiguration」,服務幫助頁面正常工作。 我絕對錯過了這裏的一些東西,也許有些事情很簡單。 任何幫助將不勝感激

回答

1

我採取了carlosfigueira的建議,痛苦地刪除我的配置設置一次一個。

我改變了我的配置設置從

舊代碼

<bindings> 
      <webHttpBinding> 
       <!-- buffer: 64KB; max size: 64MB --> 
       <binding name="StreamedBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
         receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed" 
         maxBufferPoolSize="67108864" maxBufferSize="65536" maxReceivedMessageSize="67108864"> 
       </binding> 
      </webHttpBinding> 
</bindings> 

最終的工作版本(transferMode = 「流」 被刪除)

<bindings> 
<webHttpBinding> 
<binding name="StreamedBinding" maxReceivedMessageSize="67108864" /> 
</webHttpBinding> 
</bindings> 

最終服務幫助頁面回來了。

但是我不明白爲什麼它和它關閉的原因相同。無論如何,這是我的案例的工作解決方案。 希望有人會發現它有幫助。

0

你是什麼意思,說它停止工作?在下面的示例中,幫助頁面仍然由服務返回(並且我嘗試使用IE和Chrome,並且能夠看到該頁面)。

public class StackOverflow_5937029 
{ 
    [ServiceContract] 
    public interface ITest 
    { 
     [WebGet] 
     int Add(int x, int y); 
    } 
    public class Service : ITest 
    { 
     public int Add(int x, int y) 
     { 
      return x + y; 
     } 
    } 
    static void SendRequest(string address) 
    { 
     HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(address); 
     req.Method = "GET"; 

     HttpWebResponse resp; 
     try 
     { 
      resp = (HttpWebResponse)req.GetResponse(); 
     } 
     catch (WebException e) 
     { 
      resp = (HttpWebResponse)e.Response; 
     } 

     Console.WriteLine("HTTP/{0} {1} {2}", resp.ProtocolVersion, (int)resp.StatusCode, resp.StatusDescription); 
     foreach (string headerName in resp.Headers.AllKeys) 
     { 
      Console.WriteLine("{0}: {1}", headerName, resp.Headers[headerName]); 
     } 

     Console.WriteLine(); 
     Stream respStream = resp.GetResponseStream(); 
     Console.WriteLine(new StreamReader(respStream).ReadToEnd()); 

     Console.WriteLine(); 
     Console.WriteLine(" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* "); 
     Console.WriteLine(); 
    } 
    public static void Test() 
    { 
     string baseAddress = "http://" + Environment.MachineName + ":8000/Service"; 
     ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)); 
     WebHttpBehavior behavior = new WebHttpBehavior 
     { 
      HelpEnabled = true 
     }; 
     WebHttpBinding binding = new WebHttpBinding 
     { 
      TransferMode = TransferMode.Streamed 
     }; 
     host.AddServiceEndpoint(typeof(ITest), binding, "").Behaviors.Add(behavior); 
     host.Open(); 
     Console.WriteLine("Host opened"); 

     SendRequest(baseAddress + "/Add?x=4&y=8"); 
     SendRequest(baseAddress + "/help"); 

     Console.Write("Press ENTER to close the host"); 
     Console.ReadLine(); 
     host.Close(); 
    } 
} 
+0

請參閱更新,它可能不只是因爲傳輸模式,而是配置設置中的一些基本配置 – 2011-05-13 05:18:26

+0

嘗試從空綁定配置開始,查看幫助頁是否仍然顯示;如果沒有,則一次添加一個屬性,直到添加一個導致其消失的屬性。這應該給你更多關於這個問題的信息。 – carlosfigueira 2011-05-13 06:16:23