1

I have an iOS/Android Xamarin project that share a PCL project.

I have added a web reference to the PCL via ASMX as per Xamarin's Tutorial. The tutorial doesn't say how to get to the "Add Web Reference" window, but we found it by right-clicking our PCL project and going to Add->Web Reference.

On adding the web reference I get a roughly 500 line Reference.cs file that is added to the PCL.

However, on compilation, either iOS or Android, I am given several of these errors:

Reference.cs(74,74): Error CS0234: The type or namespace name IExtensibleDataObject' does not exist in the namespaceSystem.Runtime.Serialization'. Are you missing an assembly reference? (CS0234) (MyProject)

It is clear that I need to add the System.Runtime.Serialization assembly reference. However I cannot figure out how to do this and I have spent hours looking for documentation or any relevant solution. Most posts questions appear tangental at best.

This forum post references this issue, but give no solution other than it was supposedly “fixed” three years ago.

Now the aforementioned tutorial references an "Add References…" dialog box for adding the System.Web.Services.dll if you use "Add files" to add the proxy. However, I cannot find this dialog anywhere in the IDE.

I did find "Edit References" when right-clicking on references. This produced a window with these tabs:

enter image description here

Guessing that the assembly needs to be added here I search for it, but find nothing. Apparently there is no way to add assemblies that are packaged with the IDE, you're expected to "just know" where to find them. Searching for documentation proves fruitless.

Via one of the sample project, I was able to locate the .dll file at /Library/Frameworks/Mono.framework/Versions/4.4.2/lib/mono/xbuild-frameworks/.NETPortable/v4.5/Profile/Profile78/System.Runtime.Serialization.dll and manually add it via the .NET Assembly tab.

A colleague tried adding the reference via NuGet as well.

Unfortunately the compile errors remain after attempting either approach.

Also, of note, it appears that the ToDoASMX example project nor the folder containing the System.Runtime.Serialization.dll have any references to the System.Web.Services.dll that the tutorial mentions.

BergQuester
  • 6,167
  • 27
  • 39
  • What version of C# are you running? – Alex Krupka Aug 04 '16 at 23:08
  • @AlexKrupka All three projects say "default" for the C# version. I am using Xamarin Studio Community 6.0.2 (build 73) I'm not sure what the IDE's default is, but looks like version 6 is supported. – BergQuester Aug 04 '16 at 23:58
  • How are you adding the service reference? Are you creating a proxy? Are you just right clicking and "Add Web Service"? Can you put reproduction steps into your question so we can investigate further? – Jon Douglas Aug 05 '16 at 16:22
  • Thank you, @JonDouglas for reaching out. I've added additional detail to the question. – BergQuester Aug 05 '16 at 16:51
  • I believe these docs are referring to using them in `Xamarin.iOS` and `Xamarin.Android`(At least for the `.asmx` docs). You can get to `System.Runtime.Serialization` via right clicking `References` in your `Xamarin.iOS / Xamarin.Android` project, Going to `Edit References`, then going to the `All` tab which it should be listed under the `BCL` (Base Class LIbrary). You may need to go the route of using a `Interface` based pattern within your PCL to call the respective native web service instead. You could also try wrapping your .asmx into a REST service and using `HttpClient` as well. – Jon Douglas Aug 05 '16 at 17:05
  • Seeing this sample project shows the `Interface` based pattern described above using `ISoapService` in the PCL and implementing in the native projects. You will see each project (Droid/iOS) have the `Web Reference` in them. The PCL is purely invoking the code. – Jon Douglas Aug 05 '16 at 17:12
  • Gotcha. We'll give that a try. Thank you. It is very strange to me that in order to use a PCL you would have to duplicate effort and code, even if it is generated, like this. – BergQuester Aug 05 '16 at 17:16
  • It's more of a limitation of using `.asmx` given the framework built around them. Using `WCF` or `REST` have better options for consuming directly from a PCL. However note that PCLs are going to be replaced by `NetStandard` libraries. – Jon Douglas Aug 05 '16 at 17:19

1 Answers1

2

I believe these docs are referring to using them in Xamarin.iOS and Xamarin.Android(At least for the .asmx docs). You can get to System.Runtime.Serializationvia right clicking References in your Xamarin.iOS/ Xamarin.Android project, Going to Edit References, then going to the All tab which it should be listed under the BCL (Base Class LIbrary). You may need to go the route of using an Interface based pattern within your PCL to call the respective native web service instead. You could also try wrapping your .asmx into a REST service and using HttpClient as well.

Seeing this sample project(https://developer.xamarin.com/samples/xamarin-forms/WebServices/TodoASMX/) shows the Interface based pattern described above using ISoapService in the PCL and implementing in the native projects. You will see each project (Droid/iOS) have the Web Reference in them. The PCL is purely invoking the code.

It's more of a limitation of using .asmx given the framework built around them. Using WCF or REST have better options for consuming directly from a PCL. However note that PCLs are going to be replaced by NetStandard library flavor.

Jon Douglas
  • 13,006
  • 4
  • 38
  • 51