1

在我的项目中,一个 wcf RESTful 服务,它允许用户将照片上传到 Web 服务。

更改配置设置以允许大文件上传后。(添加绑定配置,即“TransferMode”、“BufferSize”等)所有 Operation 合约都按预期工作。

但是,端点的服务帮助页面停止工作。

一旦我删除端点上的绑定配置设置,帮助页面就会返回

我该如何解决这个问题?我错过了哪里

谢谢你们

<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”,服务帮助页面可以正常工作。我肯定在这里错过了一些东西,也许是一些简单的东西。任何帮助将不胜感激

4

2 回答 2

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="Streamed" 已删除)

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

终于服务帮助页面回来了。

但是我不明白为什么它和它被关闭的原因一样。

无论如何,这是我的情况的工作解决方案。希望有人会发现它有帮助。

于 2011-05-16T09:53:18.933 回答
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();
    }
}
于 2011-05-12T20:37:45.713 回答