Hi, I develop xamarin forms app and I need a WCF Service to connect to my app. The only service support now is Azure and it costs a lot! I want to use WCF but it doesn't work :(
Hi @talnurani, would it be a feasible workaround for you if you use the "Add Service Reference" in a .NET Framework console app or the WCF Connected Service in a .NET Core console app to get the service reference file generated (reference.cs) and then copy the file to your Xamarin project? Certainly, you will also need to manually add assembly references like System.ServiceModel.dll and System.Runtime.Serialization to your Android or iOS projects. The UWP project has built in "Add Service Reference" support, so you don't need this work around.
Ok. I'll try this.
Hello.
I reference .NET standard project from Android project.
In .NET standard project I make a call to WCF service using WCF Connected Service and I've got same exception as was mentioned in #1804
`Operation 'methodNameAsync' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message.
at System.ServiceModel.Dispatcher.OperationFormatter.Validate (System.ServiceModel.Description.OperationDescription od, System.Boolean isRpc, System.Boolean isEncoded) [0x0005a] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:79
at System.ServiceModel.Dispatcher.OperationFormatter..ctor (System.ServiceModel.Description.OperationDescription od, System.Boolean isRpc, System.Boolean isEncoded) [0x00006] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:55
at System.ServiceModel.Description.ContractDescription.PopulateClientOperation (System.ServiceModel.Dispatcher.ClientRuntime proxy, System.ServiceModel.Description.OperationDescription od, System.Boolean isCallback) [0x001e0] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Description/ContractDescription.cs:226
at System.ServiceModel.Description.ContractDescription.FillClientOperations (System.ServiceModel.Dispatcher.ClientRuntime proxy, System.Boolean isCallback) [0x00055] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Description/ContractDescription.cs:183
at System.ServiceModel.Description.ContractDescription.CreateClientRuntime (System.Object callbackDispatchRuntime) [0x0002d] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Description/ContractDescription.cs:172
at System.ServiceModel.Description.ServiceEndpoint.CreateClientRuntime (System.Object callbackDispatchRuntime) [0x00002] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel.Description/ServiceEndpoint.cs:142
at System.ServiceModel.MonoInternal.ClientRuntimeChannel..ctor (System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.ChannelFactory channelFactory, System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:89
at System.ServiceModel.ChannelFactory1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) [0x00036] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory_1.cs:157
at System.ServiceModel.ChannelFactory1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address) [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory_1.cs:115
at System.ServiceModel.ChannelFactory1[TChannel].CreateChannel () [0x00006] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ChannelFactory_1.cs:110
Hi All,
Getting the same error (please see below) but my circumstances are a little different. I am calling the WCF service from the .Net Core application, I have made the reference using the WCF connected Service. When i deploy my application (.net core calling WCF) on windows environment all works like a charm, however when i deploy the same application on Linux (running .net Mono) the same code through this error :
System.InvalidOperationException: Operation 'methodNameAsync' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message.n at System.ServiceModel.Dispatcher.OperationFormatter.Validate (System.ServiceModel.Description.OperationDescription od, Boolean isRpc, Boolean isEncoded) <0x40cf3c60 + 0x0018c> in 1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) <0x40cf06a0 + 0x0022a> in <filename unknown>:0 \n at System.ServiceModel.ChannelFactory1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address) <0x40cf0670 + 0x00022> in 1[TChannel].CreateChannel () <0x40ceb4f0 + 0x00055> in <filename unknown>:0 \n at System.ServiceModel.ClientBase1[TChannel].CreateChannel () <0x40ceb480 + 0x00027> in 1[TChannel].get_InnerChannel () <0x40ceb2f0 + 0x00049> in <filename unknown>:0 \n at System.ServiceModel.ClientBase1[TChannel].Close () <0x40ceb2b0 + 0x00014> in
the problem is I am not even calling the "methodNameAsync" instead calling another method "methodNameAnotherAsync".
Any help will be highly appreciated.
Regards,
Haroon
Looks like an issue in WCF mono implementation that is not owned by WCF team.
Adding @marek-safar and @akoeplinger from Xamarin team. There are multiple reports of the "methodNameAsync" issue. Can you loop in right folks to take a look?
Thanks @zhenlan ,
I ended up using the wsdl tool to generate the proxy for WCF service and deployed that on mono and it worked fine.
However a fix for the issue would be highlight appreicated.
Regards,
Haroon
Re the methodNameAsync issue, see https://bugzilla.xamarin.com/show_bug.cgi?id=13074
@hlaghari Which WSDL tool did you use? I tried to use the SLsvcUtil.exe, but all it returns is _Error: Object reference not set to an instance of an object._ (using Visual Studio 2017 on Windows 10, btw)
I've a windows hosted service that provides a mex HTTP address. I want to use the proxy in a Xamarin.Forms project that targets netstandard2.0
Could anybody explain how to archive this?
@zhenlan is there any news on this subject? It is a VERY big problem for me, as I am tasked with making a mobile (Xamarin.Forms) solution for some existing WCF services, at it is not a viable option to rewrite the service, eg. by using REST or something similar.
I find it very strange, that Xamarin is STILL not supporting Microsofts primary network communication choice for stateful services.
Hi @HiveTyrant ,
Please see this article on WSDL (Web Services Description Language Tool (Wsdl) , Please ignore the line where it says the Clients should be created using the WCF
This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation .
I had the issue where i wanted to call the WCF service from a .net Core REST API and for that i needed the service reference and initially used the WCF connected services for .net Core t generate the reference from inside of the VS.
But as things are not yet fully supported on MONO so i ended up generating the client using wsdl.exe from command line.
Hope this helps.
@HiveTyrant, sorry, I started some conversation but it did not get much traction so far. It involves multiple teams outside of WCF...
A long-term option is probably to use a .NET Standard library, which is supported by the WCF Connected Service already and can contain a generated WCF proxy, in a Xamarin project. But unfortunately, this is currently broken due to #2463.
I tried generating the Reference from a .Net Console app and i get the same error:
"... contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message"
Hi guys, i finally found a workaround for this...
I commented all the "${Method}Async" Methods and what they depend on (I know, it's a lot) on the Reference.cs generated file, and Synchronous methods do work.
I put them on a Task.Run to run asynchronously and it is working for me. I do even have Windows authentication working now.
// CODEGEN: Generating message contract since element name x from namespace http://tempuri.org/ is not marked nillable
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/AMethod", ReplyAction = "*")]
Service.MyService.AMethodResponse AMethod(Service.MyService.AMethodRequestrequest);
/*
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/AMethod", ReplyAction="*")]
System.Threading.Tasks.Task<Service.MyService.AMethodResponse> AMethodAsync(Service.MyService.AMethodRequest request);
*/
And now i can invoke every method like this:
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
var client = new MyService.MyServiceSoapClient(binding, new EndpointAddress("http://myDirection/MyService.asmx"));
client.ClientCredentials.UserName.UserName = "WindowsAuthUserandDomain";
client.ClientCredentials.UserName.Password = "WindowsAuthPassword";
var stringResult = await Task.Run(() => client.MyMethod());
return stringResult;
I hope this helps someone since Microsoft doesn't seem to be Working on this problem on Xamarin Forms .Net Standard projects.
@kevinrodriguez-io You can generate synchronous functions only using the /syncOnly switch:
svcutil.exe /syncOnly http://localhost/<servicename>.svc?wsdl
Then you don't have to manually delete the async methods.
@wbayever That's even better!
The solution would be to generate the service with only synchronous calls and test it!
I was able to generate a working proxy class with wsdl.exe, for example:
wsdl /language:CS https://<Server Name>/reportserver/reportservice2010.asmx?wsdl
I had to add references to System.Web.Services.dll, but otherwise it was plug and play.
The correct way to do this is by using a .NET Standard project, which is supported by the WCF Connected Service. Doing this will currently give you a runtime error because mono does not fully supporting WCF's implementation of .NET Standard (as described in #2463). Closing this issue because at this point it's a duplicate of #2463.
Most helpful comment
@kevinrodriguez-io You can generate synchronous functions only using the /syncOnly switch:
svcutil.exe /syncOnly http://localhost/<servicename>.svc?wsdlThen you don't have to manually delete the async methods.