开发者

WCF REST Going over Max URL Length causes error

I am trying to create a logging service using WCF Rest. It looks something like this:

[ServiceContract]
public interface ILoggingService
{
    [OperationContract, WebGet(UriTemplate = "/LogError?m={message}")]
    void Log(string message);
}

I have increased the limits in the configuration file so you can log a fair amount of text. However if I go over this limit the service does not accept the message. So far I have made sure that the text is below the limit but this is a poor work around. How do I get around this problem in WCF REST.

UPDATE

After further investigation, I should end up with something that looks like this?

[ServiceContract]
public interface ILoggingService
{
    [OperationContract, WebGet(UriTemplate = "/LogError?m={message}", Method = "POST")]
    void Log(string message);
}

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Method = "POST";
request.Content开发者_开发百科Type = "text/plain";


I would recommend not using a GET method. The operation you are performing is a write, not a read. If you use POST, you can send an entity body using the media type text/plain. That way you are not limited by the url length.


For a http post I think the signature would look like

    [OperationContract]
    [WebInvoke(UriTemplate = "LogError",Method="POST")]
    void Log(string message);

Using posts sends the data in the http request and not in the url.

Http get request should only be used to read data, post for creation, put for updating and delete for deletion.

http://en.wikipedia.org/wiki/Representational_State_Transfer

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜