简体   繁体   English

如何在wcf数据服务中执行基于大量基于rest的url?

[英]how to execute huge rest based url in wcf data services?

I'm using Wcf data service(V3). 我正在使用Wcf数据服务(V3)。 From IOS App they will send Signature through URL. 他们将从IOS App通过URL发送签名。 Problem is sometimes user enters long signature in that situation it is giving an error like "Url is too long" . 问题是在这种情况下,有时用户输入长签名会出现类似“ URL太长”的错误。 how can i fix this issue on wcf data services. 如何在WCF数据服务上解决此问题。

Advance Thanks. 提前谢谢。

If the message client want to give to service is large, it is recommended to use POST. 如果客户端希望提供服务的消息很大,建议使用POST。

You can find the guide for Actions in WCF Data Service V3 here: http://blogs.msdn.com/b/odatateam/archive/2011/10/17/actions-in-wcf-data-services.aspx 您可以在此处找到WCF数据服务V3中的操作指南: http : //blogs.msdn.com/b/odatateam/archive/2011/10/17/actions-in-wcf-data-services.aspx

And here is quick demo for setting up a WCF DS service with Action support: 这是在Action支持下设置WCF DS服务的快速演示:

public class Service : DataService<Context>, IServiceProvider 
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceActionAccessRule("*", ServiceActionRights.Invoke);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
    }

    public object GetService(Type serviceType)
    {
        return typeof(IDataServiceActionProvider) == serviceType ? new ActionProvider() : null;
    }
}

public class ActionProvider : IDataServiceActionProvider, IDataServiceActionResolver
{
    private static List<ServiceAction> actions;

    static ActionProvider()
    {
        ServiceAction movieRateAction = new ServiceAction(
             "Action1", // name of the action 
             ResourceType.GetPrimitiveResourceType(typeof(string)), // no return type i.e. void 
             null, // no return type means we don’t need to know the ResourceSet so use null. 
             OperationParameterBindingKind.Never,
             new ServiceActionParameter[] { 
              new ServiceActionParameter("val", ResourceType.GetPrimitiveResourceType(typeof(string))) 
           }
            );
        movieRateAction.SetReadOnly();

        actions = new List<ServiceAction>() { movieRateAction };
    }

    public IEnumerable<ServiceAction> GetServiceActions(DataServiceOperationContext operationContext)
    {
        return actions;
    }

    public bool TryResolveServiceAction(DataServiceOperationContext operationContext, string serviceActionName,
                                        out ServiceAction serviceAction)
    {
        serviceAction = null;
        return false;
    }

    public IEnumerable<ServiceAction> GetServiceActionsByBindingParameterType(DataServiceOperationContext operationContext,
                                                               ResourceType bindingParameterType)
    {
        return Enumerable.Empty<ServiceAction>();
    }

    public IDataServiceInvokable CreateInvokable(DataServiceOperationContext operationContext, ServiceAction serviceAction,
                                                 object[] parameterTokens)
    {
        return new DataServiceInvokable(parameterTokens);
    }

    public bool AdvertiseServiceAction(DataServiceOperationContext operationContext, ServiceAction serviceAction, object resourceInstance, bool resourceInstanceInFeed, ref ODataAction actionToSerialize)
    {
        actionToSerialize = null;
        return false;
    }

    public bool TryResolveServiceAction(DataServiceOperationContext operationContext, ServiceActionResolverArgs resolverArgs, out ServiceAction serviceAction)
    {
        serviceAction = actions[0];
        return true;
    }
}

 public class DataServiceInvokable : IDataServiceInvokable
 {
     private readonly object[] parameters;
     private string result;

     public DataServiceInvokable(object[] parameters)
     {
         this.parameters = parameters;
     }

     public object GetResult()
     {
         return result;
     }

     public void Invoke()
     {
         result = parameters[0] as string;
     }
 }

Then you could send a POST request to http://example.org/service.svc/Action1 然后,您可以将POST请求发送到http://example.org/service.svc/Action1

Header: Content-Type: Application/json 标题:内容类型:Application / json

Request Body: {"val":"MessageToPostHere..."} 请求正文:{“ val”:“ MessageToPostHere ...”}

If you are using .Net 4.0 or above, you could experiment with your web.config settings file, with this: 如果您使用的是.Net 4.0或更高版本,则可以使用以下方法尝试使用web.config设置文件:

<system.web>
...
    <httpRuntime maxUrlLength="500" />
....
</system.web>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM