Rest from PCL

Is it possible to create all my rest request in the PCL, e.g. with RestSharp? What I want to avoid is having to implement my Rest-Calls for each platform again.

Tagged:

Answers

  • GeraldVersluisGeraldVersluis NLUniversity ✭✭✭✭

    Sure you can!

    Have a look at PortableRest also I have discovered refit lately. This even does more work for you!

  • hot33331hot33331 USMember ✭✭

    Hi Gerald, thanks for your answer, I used PortableRest, however when I start my application I get the following exception:

    2016-01-27 10:50:55.300 AppNameiOS[1658:18827] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7ba7cea0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
    Unhandled Exception:

    System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

    2016-01-27 10:51:09.939 AppNameiOS[1658:18827]
    Unhandled Exception:
    System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
    File name: 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    at PortableRest.RestClient.set_HttpHandler (System.Net.Http.HttpMessageHandler value) [0x00007] in :0
    at PortableRest.RestClient..ctor () [0x0002a] in :0
    at AppName.Utilities.Base.RestBase.get_Client () [0x0007e] in c:\Users\hot33331\Documents\Visual Studio 2013\Projects\msg-xamarin-src\AppName\AppName\Utilities\Base\RestBase.cs:96
    at AppName.Session.Authentication+d__17.MoveNext () [0x000e8] in c:\Users\hot33331\Documents\Visual Studio 2013\Projects\msg-xamarin-src\AppName\AppName\Session\Authentication.cs:324
    --- End of stack trace from previous location where exception was thrown ---
    at Sys
    tem.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2377/73229919/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:994
    at UIKit.UIKitSynchronizationContext+c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIKitSynchronizationContext.cs:24
    at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/Foundation/NSAction.cs:163
    at (wrapper managed-to-native) UIKit.UIApplication:UIApplicati
    onMain (int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:77
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:61
    at AppName.iOS.Application.Main (System.String[] args) [0x00001] in c:\Users\hot33331\Documents\Visual Studio 2013\Projects\msg-xamarin-src\AppName\AppName.iOS\Main.cs:17
    2016-01-27 10:51:09.939 AppNameiOS[1658:18827] Unhandled managed exception:
    Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. (System.IO.FileNotFoundException)
    at PortableRest.RestClient.set_HttpHandler (System.Net.Http.HttpMessageHandler value) [0x00007] in :0
    at PortableRest.RestC
    lient..ctor () [0x0002a] in :0
    at AppName.Utilities.Base.RestBase.get_Client () [0x0007e] in c:\Users\hot33331\Documents\Visual Studio 2013\Projects\msg-xamarin-src\AppName\AppName\Utilities\Base\RestBase.cs:96
    at AppName.Session.Authentication+d__17.MoveNext () [0x000e8] in c:\Users\hot33331\Documents\Visual Studio 2013\Projects\msg-xamarin-src\AppName\AppName\Session\Authentication.cs:324
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2377/73229919/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framewo
    rk/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:994
    at UIKit.UIKitSynchronizationContext+c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIKitSynchronizationContext.cs:24
    at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/Foundation/NSAction.cs:163
    at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:77
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:61
    at AppName.iOS.Application.Main (System.String[] args) [0x00001] in
    c:\Users\hot33331\Documents\Visual Studio 2013\Projects\msg-xamarin-src\AppName\AppName.iOS\Main.cs:17
    2016-01-27 10:51:09.940 AppNameiOS[1658:18827] critical: Stacktrace:

    2016-01-27 10:51:09.940 AppNameiOS[1658:18827] critical:
    Native stacktrace:

    2016-01-27 10:51:09.996 AppNameiOS[1658:18827] critical: 0 AppNameiOS 0x001bdee7 mono_handle_native_sigsegv + 311
    2016-01-27 10:51:09.996 AppNameiOS[1658:18827] critical: 1 AppNameiOS 0x001c5b11 sigabrt_signal_handler + 145
    2016-01-27 10:51:09.996 AppNameiOS[1658:18827] critical: 2 libsystem_platform.dylib 0x0915001b sigtramp + 43
    2016-01-27 10:51:09.996 AppNameiOS[1658:18827] critical: 3 ??? 0xffffffff 0x0 + 4294967295
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 4 libsystem_c.dylib 0x08ee465d abort + 156
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 5 AppNameiOS 0x00354d86 xamarin_unhandled_exc
    eption_handler + 342
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 6 AppNameiOS 0x001be76b mono_invoke_unhandled_exception_hook + 91
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 7 AppNameiOS 0x001bd5cd mono_handle_exception_internal + 6061
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 8 AppNameiOS 0x001bbe19 mono_handle_exception + 41
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 9 AppNameiOS 0x0015614e mono_x86_throw_exception + 142
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 10 ??? 0x161d8f57 0x0 + 371035991
    2016-01-27 10:51:09.997 AppNameiOS[1658:18827] critical: 11 ??? 0x1a3c9004 0x0 + 440176644
    2016-01-27 10:51:09.998 AppNameiOS[1658:18827] critical: 12 ??? 0x1a3c8fb3 0x0 + 440176563
    2016-01-27 10:51:09.998 AppNameiOS[1658:18827] critical: 13
    ??? 0x1a3c8ef9 0x0 + 440176377
    2016-01-27 10:51:09.998 AppNameiOS[1658:18827] critical: 14 ??? 0x163c985a 0x0 + 373069914
    2016-01-27 10:51:09.998 AppNameiOS[1658:18827] critical: 15 AppNameiOS 0x001cbac3 mono_jit_runtime_invoke + 707
    2016-01-27 10:51:09.998 AppNameiOS[1658:18827] critical: 16 AppNameiOS 0x0028a8df mono_runtime_invoke + 127
    2016-01-27 10:51:09.998 AppNameiOS[1658:18827] critical: 17 AppNameiOS 0x000abfc1 _ZL30native_to_managed_trampoline_1P11objc_objectP13objc_selectorPP11_MonoMethodPKcS7
    + 257
    2016-01-27 10:51:09.998 AppNameiOS[1658:18827] critical: 18 AppNameiOS 0x000b045a -[MonoMac_NSAsyncActionDispatcher xamarinApplySelector] + 74
    2016-01-27 10:51:09.999 AppNameiOS[1658:18827] critical: 19 libobjc.A.dylib 0x08978059 -[NSObject performSelector:withObject:] + 70
    2016-01-27 10:51:09.999 AppNameiOS[1658:1
    8827] critical: 20 Foundation 0x00f070d8 __NSThreadPerformPerform + 323
    2016-01-27 10:51:09.999 AppNameiOS[1658:18827] critical: 21 CoreFoundation 0x0084f6ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
    + 15
    2016-01-27 10:51:09.999 AppNameiOS[1658:18827] critical: 22 CoreFoundation 0x00845328 __CFRunLoopDoSources0 + 424
    2016-01-27 10:51:09.999 AppNameiOS[1658:18827] critical: 23 CoreFoundation 0x008447a8 __CFRunLoopRun + 1032
    2016-01-27 10:51:09.999 AppNameiOS[1658:18827] critical: 24 CoreFoundation 0x008440e6 CFRunLoopRunSpecific + 470
    2016-01-27 10:51:09.999 AppNameiOS[1658:18827] critical: 25 CoreFoundation 0x00843efb CFRunLoopRunInMode + 123
    2016-01-27 10:51:09.999 AppNameiOS[1658:18827] critical: 26 GraphicsServices 0x0b0e5664 GSEventRunModal + 192
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 27 GraphicsServices
    0x0b0e54a1 GSEventRun + 104
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 28 UIKit 0x03259bfa UIApplicationMain + 160
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 29 ??? 0x18e9b2f0 0x0 + 417968880
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 30 ??? 0x18e9b0e8 0x0 + 417968360
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 31 ??? 0x18e9b070 0x0 + 417968240
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 32 ??? 0x18e9ada4 0x0 + 417967524
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 33 ??? 0x18e9af38 0x0 + 417967928
    2016-01-27 10:51:10.000 AppNameiOS[1658:18827] critical: 34 AppNameiOS 0x001cbac3 mono_jit_runtime_invoke + 707
    2016-01-27 10:51:10.001 AppNameiOS[1658:18827] critical: 35 AppNameiOS 0
    x0028a8df mono_runtime_invoke + 127
    2016-01-27 10:51:10.001 AppNameiOS[1658:18827] critical: 36 AppNameiOS 0x0028f8f1 mono_runtime_exec_main + 401
    2016-01-27 10:51:10.001 AppNameiOS[1658:18827] critical: 37 AppNameiOS 0x0028f6b5 mono_runtime_run_main + 629
    2016-01-27 10:51:10.001 AppNameiOS[1658:18827] critical: 38 AppNameiOS 0x0014daed mono_jit_exec + 93
    2016-01-27 10:51:10.001 AppNameiOS[1658:18827] critical: 39 AppNameiOS 0x0036f6d1 xamarin_main + 2497
    2016-01-27 10:51:10.001 AppNameiOS[1658:18827] critical: 40 AppNameiOS 0x00370031 main + 65
    2016-01-27 10:51:10.002 AppNameiOS[1658:18827] critical: 41 libdyld.dylib 0x08e3da21 start + 1

    2016-01-27 10:51:10.002 AppNameiOS[1658:18827] critical:

    Got a SIGABRT while executing native code. This usually indicates
    a fatal error in the mono runtime o
    r one of the native libraries

    used by your application.

    Did you have a similar experience when using PortableRest? Could you give me a hint on how to solve this?

  • GeraldVersluisGeraldVersluis NLUniversity ✭✭✭✭

    Did you include the PortableRest library in both your shared project as well as your platform specific project?

  • alarghialarghi ARMember

    Check my Request class http client, It may help you https://github.com/4gus71n/Xamarin.Droid

Sign In or Register to comment.