繁体   English   中英

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

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

我正在使用Wcf数据服务(V3)。 他们将从IOS App通过URL发送签名。 问题是在这种情况下,有时用户输入长签名会出现类似“ URL太长”的错误。 如何在WCF数据服务上解决此问题。

提前谢谢。

如果客户端希望提供服务的消息很大,建议使用POST。

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

这是在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;
     }
 }

然后,您可以将POST请求发送到http://example.org/service.svc/Action1

标题:内容类型:Application / json

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

如果您使用的是.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