开发者

unable to load wcf restful help page after changing transferMode to "Streamed"

开发者 https://www.devze.com 2023-03-04 03:45 出处:网络
In my project, a wcf restful service, which allow users to upload photos to the web service. After changing config settings to allow large file upload. (add binding configuration, i.e. \"TransferMode

In my project, a wcf restful service, which allow users to upload photos to the web service.

After changing config settings to allow large file upload. (add binding configuration, i.e. "TransferMode", "BufferSize", etc.) All Operation contracts are all working as expected.

However, the service help page for the endpoint stopped working.

The help page comes back, once I remove the binding config setting on my endpoint

How can I fixed this?? where did i missed

thank you all

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

Upd开发者_运维知识库ate: I think it is not just because of the transfer mode, but maybe some other setting as well. The service help page comes back once I remove the "bindingConfiguration" in the code above. I have 2 endpoints. The other endpoint don't have the "bindingConfiguration", and the service help page works fine on that. I definitely missed some thing here, maybe some thing simple. any help will be greatly appreciated


I took carlosfigueira advice, painfully removed my config setting one at a time.

I changed my config settings from

OLD Code

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

To Final working version (transferMode="Streamed" is removed)

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

finally the service help page is back.

However I can't understand why it is back same as why it was turned off.

anyway, this is the working solution for my case. hope someone would find it helpful.


What do you mean by saying that it stops working? In the example below the help page is still returned by the service (and I tried using both IE and Chrome, and they were able to see the page).

    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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号