Consuming WCF service in Xamarin WIndows Phone project - wcf

I have a bit of a problem with my Xamarin.Forms project. I have generated web service proxy class with SlSvcutil.exe and have imported that class in my PCL library that is shared amongs platform specific projects / iOs, Android and WindowsPhone.
All the references from System.ServiceModel are missing because, ofcourse, that reference does not exist in my project. How do I add it? I tried to do it with NuGet but it just fails all the time with same error.
You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I tried selecting 'Ignore All' for Dependacy Behavior when installing package but to no avail.
This is driving me crazy as I have so much problems with this Xamarin and I havent really started programming yet.

You should not need to install an extra package. Just add System.ServiceModel, System.Runtime.Serialization and System.Xml to your references. If you need to, you can just open your csproj file in a text editor and add these to the same area where you see other references in the file:
<Reference Include="System.ServiceModel" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
And make sure that you are using slsvcutil.exe from the Silverlight 5 SDK, not an older one. Taking a look at a working WCF client in one of our projects, I see this exact tool version:
// This code was auto-generated by SlSvcUtil, version 5.0.61118.0

Related

.NET 7 dependencies and nuget packages managing

I've started a new .NET 7 project in Visual Studio 2022. The template I used was "ASP.NET Core WebAPI". The project turned out to look like this in the solution explorer:
I can see that there is a dependency upon a series of DLLs in the folder "C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\7.0.2\ref\net7.0". When I browse to this folder and grab, for instance, the "Microsoft.AspNetCore.Http.Abstractions.dll" assembly I see its version as 7.0.22..... which makes sense.
What is weird is that when I click "Manage NuGet Packages" on this project I see absolutely no NuGet package already installed. It looks like this dependency mechanism is something independent of NuGet.
Now I want to create a class library that will encapsulate some common functionality I'd like to share across the projects but it needs to read data from the HttpContext class, which is defined in the "Microsoft.AspNetCore.Http.Abstractions.dll" file. So how should I add this dependency?
Adding it through "dotnet add package Microsoft.AspNetCore.App" command on the class library projects seems like a waste of resources as it adds the entire bundle of dlls and I only care about .Http.Abstractons.dll and it's direct dependencies.
Plus, when I ran the command Visual Studio complained with the warning:
NETSDK1080 A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference".
Adding the dll through NuGet worked as Visual Studio was not complaining any more but the version of assembly added was 2.2.0 and not 7.0.2 as in the dotnet package. So technically, the HttpContext referenced in one projects is a different thing to the HttpContext referenced in the other project.
Please help me understand this mechanism and how should I add the dll of interest to my project to be able to access HttpContext in my library.
When should I use dotnet add package and when should I use NuGet packages management? Any good reading on this subject to bring me up to speed from .NET Framework 4.+ to .NET 7 in this area?
As .NET user for the last 10 years or so I feel so lost in the recent developments and find official docs I can find on the web of little use.
I tried adding the Microsoft.AspNetCore.App package through the "dotnet add package" command - Visual Studio complained, plus it pulled the entire bundle of assemblies but I care about only "Microsoft.AspNetCore.Http.Abstractions.dll".
I tried adding the "Microsoft.AspNetCore.Http.Abstractions" NuGet package but the version of assembly added was completely different to the one referenced in the WebAPI project.
What is weird is that when I click "Manage NuGet Packages" on this project I see absolutely no NuGet package already installed.
Those dependencies are determined by the project SDK which can be found in the root element of .csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
...
</Project>
So how should I add this dependency?
For latest versions of .NET you should reference corresponding SDK via FrameworkReference, for example to reference ASP.NET Core components you should add <FrameworkReference Include="Microsoft.AspNetCore.App"/> to library projects .csproj file as mentioned in the docs (and in the warning):
<Project Sdk="Microsoft.NET.Sdk">
<!--... rest of file-->
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<!--... rest of file-->
</Project>

Visual Studio 2013 - the system cannot find reference specified

I googled and checked existing post here but didn't find any relevant post so here is my question.
I am using VS2013 Primium edition. I have few class library projects(all using framework 4.0). When these class libraries become part of Web Solution, reference paths in the class library are shown and project compiles fine as shown below.
However, same class library project doesn't load reference paths when it becomes part of Windows Service Solution.
I doubled checked all my projects are using same framework version. Any idea whats going wrong?
finally I am able to resolve it.
After recreated my library project inside my Windows Service Solution as described here.
I opened same library project in my web solution. Somehow, my web solution adds nuGet restore tags in my library project file.
<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
These tags were causing trouble. Once I removed those tags as described here. it fixed my issue.

Xamarin Forms how to consume a wcf service

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.

Script# and WF Xaml files in the same project, can't compile

We have a VS 2010 MVC3 project, targetting .NET 4.0 (machine has .NET 4.5), the project contains a WF Xaml file and related classes. We needed to access jQueryValidation on the serverside, so we added the script# jQueryValidation NuGet package (v 0.7.5.0), we get the following compile error without even using script# yet:
Error 1 XC1020: Build error occurred in the XAML MSBuild task: 'Could not load type 'System.Runtime.CompilerServices.ScriptAssemblyAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.....
The Xaml file contains references to the standard mscorlib, we've attempted to strong reference the Gac library in Xaml, via version #...however its to no vail. The project will only compile once we remove the Script# libraries. Then in an effort to narrow down the problem, we installed the nuget package for script# 0.7.5.1, not the jQueryValidation package, and we are able to compile. Installing the jqueryvalidation package afterwards will result in the same error as before, could this be related to the package being based on 0.7.5.0?
Any hints? we would really like to use script# jqueryvalidation and WF Xaml in the same project.
Thanks in advance.
Script# assemblies are meant to be used by script# projects only, i.e. those projects that contain c# code to be compiled into javascript. Your MVC project itself is not a script# project. Likely what you should be doing is creating a separate script# project, to generate script that gets deployed into/via your MVC project.
Specifically script# comes with its own mscorlib with script# specific types not present in the desktop mscorlib assembly.

How to reference a dll that take into account the configuration and platform

We are developing a library for MonoTouch, we could use in all other MonoTouch projects. For that purpose, we have generated 4 dlls that are depending on the configuration and the platform ( Debug / Release / iPhone / iPhoneSimulator).
Then, I am trying to include those dlls in an other MonoTouch project. In Microsoft Visual Studio 2008, the trick is to add one of the dll as reference of the project and then edit manually the project file.
E.g. for one Dll, we'll change the line that reference the Dll:
<Reference Include="Blabla" ...>
...
<HintPath>..\$(Platform)\$(Configuration)\Blabla.dll</HintPath>
</Reference>
The variable $(Platform) and $(Configuration) ensures we are taking the Dll corresponding the the right configuration and platform.
I did the same thing with a MonoDevelop project, but when I reload the modified project, the referenced Dll is in red (file not found). Somebody know why? Am I missing something in the configuration of the project / solution? Is the right way to do this?