I just started working on xamarin not long ago.
Now I met a problem on Xamarin consuming AX2012 Webservice.
I’m in a project that need an android device connect with AX2012 R3 Inbound port.
I made a very simple webservice like below and tested successfully by using C# project.
AX Webservice code
[SysEntryPointAttribute(true)]
public ItemNameAlias GetItemName(ItemId itemId)
{
return InventTable::find(itemId).NameAlias;
}
C# invoke code(successful)
static void Main(string[] args)
{
TestWebservice.TestWebserviceClient client = new TestWebservice.TestWebserviceClient();
TestWebservice.CallContext cpny = new TestWebservice.CallContext() { Company = "USMF" };
client.ClientCredentials.Windows.ClientCredential.UserName = #"sagcn\wangy";
client.ClientCredentials.Windows.ClientCredential.Password = "aoc-111";
string itemName = client.GetItemName(cpny, "C0004");
Console.WriteLine($"Item Name: {itemName}");
Console.ReadKey(false);
}
When I add this service reference to an Xamarin.form project, it was been used very like in C# project.
But when the code invoked the webservice function, it throws a System.NotImplementedException exception.
System.NotImplementedException
Message=The method or operation is not implemented.
Xamarin code (throw NotImplementedException exception)
private void Button_Clicked(object sender, EventArgs e)
{
string itemName = "";
Debug.WriteLine("Start");
ASMXService.TestWebserviceClient client = new ASMXService.TestWebserviceClient();
ASMXService.CallContext cpny = new ASMXService.CallContext() { Company = "USMF" };
client.ClientCredentials.Windows.ClientCredential.UserName = #"sagcn\wangy";
client.ClientCredentials.Windows.ClientCredential.Password = "aoc-111";
// throw exception here
itemName = client.GetItemName(cpny, "C0004");
Debug.WriteLine($"Item Name: {itemName}");
Debug.WriteLine("End");
}
I searched many places but still don’t know the reasons why.
Does anyone have the same experience or can give me some advice?
Thanks a million.
AX Webservice code
C# project add web reference
C# project code success
Xamarin add WCF Webservice
Xamarin add WCF Webservice2
Xamarin invoke webservice
Error exception
Related
i programming an Application for my study.
I try to use gRPC in Xamarin.Forms.
The gRPC is in a seperate Libyry (.NET Standart 2.1).
If i use the code in WPF-Core Project every thing works fine.
But if I try to use the same in my Xamarin.Forms-Project the Connection don't work.
if I use the connectionString "http://my.server.com:5050" I get these Exception
Error starting gRPC call: unexpected end of stream on Connection{my.server.com:5050, proxy=DIRECT hostAddress=5.189.149.82 cipherSuite=none protocol=http/1.1} (recycle count=0)
if I the SSL Version"https://my.server.com:5050" I get these Exception
Error starting gRPC call: Connection closed by peer
Here is the Code of the gRPC-Libary
...
if (connectionString.Contains("http://"))
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
channel = GrpcChannel.ForAddress(connectionString);
client = new Haushaltsbuch.HaushaltsbuchClient(channel);
SuccsessReply reply = new SuccsessReply { Result = false };
try
{
reply = client.Login(new UserRequest
{
User = new GRPC_User
{
Username = username,
PassHash = passHash
}
});
}
catch (RpcException e) when (e.Status.Detail.Contains("The SSL connection could not be established"))
{
client = null;
throw new CommunicationException("Fehler mit SSL-Zertifikat des Servers", e);
}
catch (RpcException e)
{
client = null;
throw new CommunicationException("Server nicht erreichbar", e);
}
...
I am only a student and if I google, then it says that Xamarin Forms is supporting gRPC.
But why is it not working?
the .Android Project has the GRPC.Core package from NuGet istalled.
Solved it by Replacing
channel = GrpcChannel.ForAddress(connectionString);
with
if (connectionString.Contains("http://"))
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
string newConString = connectionString.Replace("http://", "");
return new Channel(newConString, ChannelCredentials.Insecure);
}
else
{
string newConString = connectionString.Replace("https://", "");
return new Channel(newConString, new SslCredentials());
}
It seems like the GrpcChannel Class isn't working on Andriod.
Update: May, 2021
Xamarin does not fully support gRPC, so be aware of this when developing your software on Xamarin.Forms.
Starting w/ gRPC version 2.34.X, gRPC has started partial support for Xamarin.Forms w/ Android and iOS devices.
Please see this for more information.
I publish with M2MQTT Paho Python library on the device as follows:
msg = "POS {} {} {} {} {} {} {}"
msgtosend=msg.format(tagNum, tagID, x_pos, y_pos, z_pos, qos, unk)
print(msgtosend)
# qos=1 - (must be when clean_session is False)
mqttinfo=rpiclient.publish("dwm/position", msgtosend, 1)
if mqttinfo.rc != 0:
print("Publishing message with ID {) failed. Error Code={}".format(mqttinfo.mid, mqttinfo.rc))
Then, I am trying to read the data in C# application again with M2MQTT C# library (after successful connection to Azure IoT Hub) as follows:
tpc[0] = "devices/MasterTag/messages/devicebound/#";
tpc[1] = "$iothub/twin/PATCH/properties/desired/#";
tpc[2] = "$iothub/methods/POST/#";
tpc[3] = "$iothub/twin/res/#";
mqttClient.Subscribe(tpc, qosArray);
where qosArray has only one item and it is either 0 or 1.
...and yet, I do not get any messages. In fact my callback MqttClient_MqttMsgSubscribed is not called either, which means that subscription was not successful and yet I get no error messages or exceptions...
try the following fix:
tpc = new string[] {
"devices/MasterTag/messages/devicebound/#",
"$iothub/twin/PATCH/properties/desired/#",
"$iothub/methods/POST/#",
"$iothub/twin/res/#"
};
qosArray = new byte[] {
MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE,
MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE,
MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE,
MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE
};
var subCode = mqttClient.Subscribe(tpc, qosArray);
First of all, hello everyone as it's my first post.
Getting to the case: I'm trying to send message between two apps - one on computer and the other on Android through Named Pipes and executing the following code ends up with an "The method or operation is not implemented" exception.
The code fragment is an Button Clicked event - the idea is to open a pipe, send through a button text (buttons texts are "Up", "Down", "Left" and "Right) and then close the pipe.
I've tested this and it works as long as the project is a WinForms project using standard System.IO.Pipes.
private void Button_Clicked(object sender, EventArgs e)
{
header.Text = "Pressed: " + (sender as Button).Text;
try
{
using (var pipeClient = new NamedPipeClientStream(SERVERNAME, "testpipe", PipeDirection.Out))
{
header.Text = "Connected with: " + SERVERNAME;
using (var stream = new StreamWriter(pipeClient))
{
pipeClient.Connect();
stream.Write((sender as Button).Text);
}
}
}
catch(Exception exc)
{
Debug.WriteLine(exc.StackTrace);
Debug.WriteLine(exc.Message);
}
}
The line creating an exception is
using (var pipeClient = new NamedPipeClientStream(SERVERNAME, "testpipe", PipeDirection.Out))
I've tested servername (const string) being an IP address, "localhost" or computer name and nothing changes.
Am I doing something wrong or is this a Xamarin error?
Looking in the mono source for NamedPipeClientStream this is only implemented for win32. So it makes sense that you are getting a NotImplementedException.
Not every API that you have available on the desktop is supported on mobile.
Instead of using NamedPipeClientStream you could use TCP Sockets or something more high level as a ASP.NET Core server exposing what you need as a RESTful API or similar and consuming it with HttpClient or any other REST client.
I'm totally new in xamarin.
I use Visual Studio 2017 Community and I write a very simple code: I want to connect to a basic WCF service.
The link to the service:
http://services.adserviceitalia.it/Service1.svc
(method GetHello, input string and return string... very basic method)
I read a lot of samples... I add a reference to the services, generate the proxy class... ok!!
public partial class MainPage : ContentPage
{
private wcfs.Service1Client ws;
public MainPage()
{
InitializeComponent();
var endpoint = new EndpointAddress("http://services.adserviceitalia.it/Service1.svc");
var binding = new BasicHttpBinding
{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
TimeSpan timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
ws = new wcfs.Service1Client(binding,endpoint);
ws.GetHelloCompleted += Handle_HelloWorldCompleted;
}
private void Button_Clicked(object sender, EventArgs e)
{
ws.GetHelloAsync("Mark");
}
private void Handle_HelloWorldCompleted(object sender, wcfs.GetHelloCompletedEventArgs args)
{
label1.Text = args.Result;
}
}
}
It works in UWP debug...
Connection with WCF... Hello World working in UWP
I got an unhandled exception in Android...
In Android Manifest all permission are cheched. The Android emulator is connected to internet...
Every help would be extremely appreciated!! Thanks in advance... and excuse me form my english.
Ops...
First: thanks to all!!
In my log i read this:
04-27 14:11:30.106 E/mono-rt ( 5308): [ERROR] FATAL UNHANDLED EXCEPTION: Android.Util.AndroidRuntimeException: Only the original thread that created a view hierarchy can touch its views.
Seems that problem is that I try to update the interface directly in Handle_HelloWorldCompleted with WCF respose:
label1.Text = args.Result;
... in I modify the code in this way:
//label1.Text = args.Result;
System.Diagnostics.Debug.WriteLine(args.Result);
I can see that arg.Result is populated by the WCF response "Hola Mark" (ergo: the connection with the service works!!) .
Notice i've this behavior in Android debug only.
How I can update that label1 ??
I have a winform program, now I need to enhance feature communicate with UWP app, so I added reference Windows.DLL and did some change for winform program, now I can call UWP app thru the method Launcher.LaunchUriAsync(), but any an exception on method Launcher.LaunchUriForResultsAsync(),
Could you provide me some advice? Thanks in advance.
Exception:
The operation identifier is not valid. (Exception from HRESULT: 0x800710DD)
Some Code:
// The protocol handled by the launched app
Uri testAppUri = new Uri("etrace.scanner:");
var supportStatus = await Launcher.QueryUriSupportAsync(testAppUri, LaunchQuerySupportType.Uri, "80a2fbc7-843e-46ca-a740-cbb1bc604d33_y890260wv9vv0");
if (supportStatus != LaunchQuerySupportStatus.Available)
{
// Check the app available or not.
}
var inputData = new ValueSet();
inputData["TestData"] = "Test data";
var optionsE = new LauncherOptions { TargetApplicationPackageFamilyName = "80a2fbc7-843e-46ca-a740-cbb1bc604d33_y890260wv9vv0" };
// Call APP successully.
bool success = await Launcher.LaunchUriAsync(testAppUri, optionsE, inputData);
Debug.WriteLine(success);
// Got an exception:
var result = await Launcher.LaunchUriForResultsAsync(testAppUri, optionsE, inputData);
You can use AppServiceConnections.
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service
They're for communication with other apps for UWP and they're supported in Win32 and work the same.