简体   繁体   中英

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

I'm using Wcf data service(V3). From IOS App they will send Signature through URL. Problem is sometimes user enters long signature in that situation it is giving an error like "Url is too long" . how can i fix this issue on wcf data services.

Advance Thanks.

If the message client want to give to service is large, it is recommended to use 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

And here is quick demo for setting up a WCF DS service with Action support:

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

Header: Content-Type: Application/json

Request Body: {"val":"MessageToPostHere..."}

If you are using .Net 4.0 or above, you could experiment with your web.config settings file, with this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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