Xamarin Forms how to consume a wcf service - wcf

I've created a Xamarin project which added the following projects to the solution:
Xamarin.UI(Portable)
Xamarin.UI.Droid
Xamarin.UI.iOS
Xamarin.UI.UWP
Xamarin.UI.Windows (Windows 8.1)
Xamarin.UI.WindowsPhone (Windows Phone 8.1)
I am having problems creating a client which can consume my WCF service.
1) Firstly the current Xamarin project template doesn't reference System.ServiceModel assembly in the PCL therefore I cannot right click the PCL and Add Service Reference to my project. When I manually add a reference to System.ServiceModel from this location - C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5 the menu item for create service reference pops up. When I click Go in the Add Service Reference dialog I get the following error:
"This service cannot be consumed by the current project. Please check if the project target framework supports this service type."
The PCL targets are as follows:
.NET Framework 4.5
ASP.NET Core 1.0
Windows 8
Windows Phone 8.1
Xamarin.Android
Xamarin.iOS
Xamarin.iOS
I don't know how to get this working ?
2) Secondly the work around I use is to create the client with SlSvcUtil.exe
Add the generated code to my PCL along with a reference to System.ServiceModel and everything builds ok. The problem is that when I run the code it flags up type reference errors ! Should I be manually adding the reference to System.ServiceModel anyway? What am I doing wrong in this scenario? Am I missing some steps?
I've checked the Xamarin docs but it seems that I can't find detailed instructions on this.
Please help me out ! Thanks:)

PCL and WCF should be supported. Alternatively, you could get this to work manually with HttpClient, etc. But maybe if you can use the shared project instead of PCL, that would be easier. Otherwise you'd have to also use DependencyService, create interfaces, etc. for each platform.

Related

How do I know if an application uses Silverlight?

I am looking at a legacy .NET application and need to know if it is using Silverlight. If it is, I need to migrate the code to WPF, XAML, or HTML5.
Is there a specific set of namespaces and references that tell me that this is a Silverlight application?
Some indicators:
the ProjectTypeGuids element in the .csproj/.vbproj files contains the Silverlight project GUID: {A1591282-1198-4647-A2B1-27E5FF5F6F3B}
the System.* dependencies, when observed in the property grid in Visual Studio, would have version 5.0.5.0 or similar.
You can see a Silverlight project property with bellow link
Silverlight project property

VS2015 C++ DLL and such with Add Reference

I have three VS2015 projects (DLL, C++ App & C# App)
I created the DLL and targeted v4.5 Framework
I created the C++ Application and targeted the v4.5 framwork and then was able to add reference without an issue.
I create the C# Application and targeted the v4.5 framework and then the Add reference fails with check your assembly or COM message.
Both applications have the DLL project added to the solution.
What else can I check as to why my C# process can't add reference?
Thanks,
Mark
I got around it using PInvode and the C# project didn't need to Add Reference afterall. I had to manually edit out the Precompiled header stuff to force that NotUsing. Thanks for the quick response... just had a quick turn around for my boss. Handed a working Cipher DLL for use with both C++ and C# in his project.

Access wcf from netcoreapp2.0

I have a asp dotnet core 2.0 project that needs to talk to a downstream WCF service
The proj file is targeting netcoreapp2.0
I have added nuget packages for System.ServiceModel.Primitives and have almost everything I need apart from something in the System.ServiceModel.Configuration namespace which doesnt appear to be available on Nuget
In the past, I have successfully talked to the WCF service in a netcore1.1 project (by making it target net461)
However, this doesnt appear to be an option if you want to take advantage of netCore2.0 functionality. If you target net461 then you cant access netcore2.0 features
Should this be possible?
Am I doing something wrong?
Can you target net461 and also use netcore2.0 features?
or is there a way I can target netcoreapp2.0 and still access System.ServiceModel.Configuration?
Or do I need to target netcoreapp2.0 and do something else that allows me to access System.ServiceModel.Configuration?
thanks
If you use at least VS 2017 version 15.5, you can add the WCF service as a connected service. The wizard will add the required packages and generate the client code. (in previous VS 2017 versions, you'd need a preview extension).
You can access this wizard from the "Add Connected Service" context menu item:

Why am I unable to add my PCL to my Universal App?

I get "Unable to add reference" when I try to add my PCL as reference. The projects are in the same solution. The error message doesn't say anything more.
When I try to add the .dll via Browse... I get the an error telling me that I can not add a PCL targeted at .NET Framework to a project targeting .NETCore.
What's wrong?
It sounds like the library you think is a PCL is not actually a Portable Class Library. It's just a .NET Framework library.
Try creating a new PCL and referencing that. See this MSDN page for information on how to create a PCL.
The error is that your PCL is targeted at .NET Framework and not .NETCore. .NETCore does only contain a subset of .NET Framework.
To solve this, replace your PCL project with a Class Library (Portable for Universal Apps).

Metro app references and types in Windows 8

I developing C#\XAML metro-ui application. I need some .NET types that doesn't included in .NET for Metro style apps or Windows references (for instance HttpUtility that is located in System.Web). I can't find System.Web via Assembly List. In same time I can refer it via Browse. But as I understand correct isn't it good way and I should avoid this, is it?
Next thing I have found description of Assembly Class. In the bottom of page in Version Information section I can see that it is supported by Portable Class Library. In the sample I see next code
Assembly assem = Assembly.GetExecutingAssembly();
But in my project Assembly doesn't have GetExecutingAssembly method. Is it documentation outdated? or I miss something?
I use Windows 8 Release Candidate and VS 2012
EDIT0: Instead of HttpUtility I should use WebUtility I know it. But I choose this type just for example.
EDIT1: I see public static System.Reflection.Assembly GetExecutingAssembly() via Object Browser but can't reach it.
Metro style apps can only call methods in the .NET Core Profile. You can see the Core Profile reference assemblies on Windows 8 RP machine at ...
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5
You can use ILDasm or ILSpy to view them. See A .NET developer's view of Windows 8 app development video from Build. He talks more about the Core Profile and why some classes, methods and interfaces were removed.