UWP Can't Get Method when i add services reference - xamarin

I have to call SOAP Webservice. But it can't call at PCL. so I use dependencyservice in Android & UWP
Android can call SOAP Webservice. but when I call add services reference in xxx.UWP, It can't call Method( = Operation) at my WSDL site.
HOW CAN CALL WEB SERVICE (SOAP) IN UWP?? PLEASE HELP ME......
This is Dependency code
using System;
using System.ServiceModel;
using System.Threading.Tasks;
using Windows.UI.ViewManagement;
using Xamarin.Forms;
[assembly: Dependency(typeof(XXXXX.UWP.DependencyService.GetWI))]
namespace XXXXX.UWP.DependencyService
{
public class GetWI : Interface.IGetWI
{
public string[] getWIValues(string item)
{
GET_WI.WISWRProviderClient Client = new GET_WI.WISWRProviderClient();
return
}
}
}
enter image description here

Related

How to register a model binder in web api?

I'm trying to register a custom model binder in Web Api, but can't seem to find the correct way to do it.
System.ArgumentException: 'The service type SimpleModelBinderProvider is not supported.'
WebApiConfig.cs
using System.Web.Http;
using System.Web.ModelBinding;
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
...
var provider = new SimpleModelBinderProvider(typeof(CustomerIdentity), new CustomerIdentityModelBinder());
config.Services.Insert(typeof(SimpleModelBinderProvider), 0, provider);
...
}
}
I've tried SimpleModelBinderProvider and ModelBinderProvider.
What is the proper way to register a custom model binder in web api?
NOTE: I'm not using the ModelBinderAttribute on the class because it's in another assembly which would cause a circular-dependency (and because I don't like decorating classes with attributes).
NOTE: Starting to think this might be namespace related. The project has both MVC5 and WebApi2 in it.
Namespace Issue
I should have been using the namespaces:
// In the WebApiConfig.
using System.Web.Http.ModelBinding;
using System.Web.Http.ModelBinding.Binders;
// For the ModelBinder itself.
using System.Web.Http.Controllers;
using System.Web.Http.ModelBinding;
using System.Web.Http.ValueProviders;
Instead of:
using System.Web.ModelBinding;
The code was near identical as well as the class names, which is why it was hard to track down and figure out.

Access Cloudscribe SiteID outside Controller or Views

I have a class which I want to get the Cloudscribe SiteId but I am unsure how to access it.
If I was using a controller then I would be able to rely on the SiteContext to be DI'd into the constructor but that does not work in this instance.
Can someone tell me how I can access the SiteId property in the code below?
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CoLabR
{
public class Messaging : Hub
{
private string _siteId;
public Messaging()
{
//Code here to get SiteID
_siteId = "<<Code for getting Site ID";
}
public Task Post(string message)
{
return Clients.Group(_siteId).InvokeAsync("Post", message);
}
public Task JoinRoom()
{
Groups.AddAsync(Context.ConnectionId, _siteId);
return Clients.Group(_siteId).InvokeAsync("Post", Context.User.Identity.Name + " joined. " + _siteId);
}
}
}
SignalR Core supports injecting into hubs so you should be able to just inject SiteContext into Messaging.
Here is a related question that shows how to do that.
Although the answer from #Pawel helped me, my final solution differed. I tried registering SiteContext in my Startup.cs and injecting SiteContext into my constructor for the Hub but it kept returning a different SiteID on each page load (or if I used Singleton it gave me the same SiteId across multiple CloudScribe Sites).
In the end my solution was to change the Hub constructor to the below code
public Messaging(SiteUserManager<SiteUser> userManager)
{
//Code here to get SiteID
_siteId = userManager.Site.Id.ToString();
}
This gave me a consistent SiteId for each Tenant site in my application.

Namespace name RecyclerView could not be found

I have been following along with Xamarin's guide, but am not able to reference RecyclerView to create an instance of it.
JDK 8 is installed. I have installed the Xamarin.Android.Support.v7.RecyclerView package and all of its dependencies. I'm targeting API level 24. But still no dice.
I can't find anything online that references this issue. Any ideas?
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.RecyclerView;
using Android.Views;
using Android.Widget;
namespace ArbanQC
{
[Activity(Label = "LoadsActivity")]
public class LoadsActivity : Activity
{
ProgressDialog progress;
bool ScheduleShowing;
RecyclerView grid; //Namespace is not recognized here.
List<Load> loads = new List<Load>();
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
RequestWindowFeature(WindowFeatures.NoTitle);
SetContentView(Resource.Layout.Loads);
grid = FindViewById<RecyclerView>(Resource.Id.loadsGrid); //Also not recognized here
ScheduleShowing = true;
}
}
}
Your using directive:
using Android.Support.V7.RecyclerView;
is incorrect - it should be:
using Android.Support.V7.Widget;

How to use the vibration service in a shared project Xamarin.Forms (Portable) in Visual Studio?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App1
{
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
}
void OnButton_Clicked(object sender, EventArgs args)
{
/* code to vibrate */
}
}
}
I have not tested this myself but the simplest solution is to use the component developed already called CrossVibrate.
In general, you just have to create an abstraction (Interface) and implement it for each OS. This component handles this for you.

Automation error on Webclient.Headers

I have an error in the following code when using the Headers property:
Public Function UploadImage(image As String) As String
Dim wc As System.WebClient
'create WebClient
Set wc = CreateObject("System.Net.WebClient")
Call wc.Headers.Add("Authorization", "Client-ID " & ClientId) <------- Error occurs here
I have repro'd your issue as far as possible. You didn't mention what the error you were getting was, but I got:
Automation error -2146233079 (80131509)
I tried using
CallByName(wc, "Headers", VbGet)
... but that just returns
Automation error 440.
Oh well...
I looked up online, and found this link. My guess is that because the base class of the WebHeaderCollection class is not COM Visible, this causes the error.
My work-around would be to wrap up this functionality in a small .NET component, and make that COM visible.
An example of this would be something like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
namespace WebClientWrapper
{
[ComVisible(true)]
[Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]
public class WebClientWrapper : WebClient
{
[ComVisible(true)]
public WebHeaderCollectionWrapper WHeaders
{
get
{
return new WebHeaderCollectionWrapper(base.Headers);
}
}
}
[ComVisible(true)]
[Guid("yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy")]
public class WebHeaderCollectionWrapper
{
WebHeaderCollection _whc;
internal WebHeaderCollectionWrapper(WebHeaderCollection whc)
{
_whc = whc;
}
[ComVisible(true)]
public void Add(string name, string value)
{
_whc.Add(name, value);
}
[ComVisible(true)]
public void Clear()
{
_whc.Clear();
}
}
}
(You will have to replace the GUIDs with your own values - use GUIDGEN.EXE).
Instantiate this component with CreateObject("WebClientWrapper.WebClientWrapper")
Now you would simply replace references to the Headers property to WHeaders (or whatever you want to call it). WHeaders gives you a true wrapper around WebHeaderCollection - you'll have to define all the other wrapped methods and properties yourself. I was hoping to define WHeaders as public WebHeaderCollectionWrapper, but that didn't seem to work.
Since WebClientWrapper inherits from WebClient, you should be able to use most of the properties and methods. Where you have troubles, just add new methods to the class wrapping up the functionality that doesn't work with VB.
Oh, and do remember to set the checkbox at Project Properties => Build => Output => Register for COM interop. And then reference the type library created.

Resources