- Home /
Question by
Vishal-Shinde · Nov 25, 2016 at 06:31 AM ·
unity5servicewcf
Consume wcf service with netTcpBinding in unity
I am trying to consume wcf service with nettcpbinding in my unity3d application but it gives an error of
Error: Exception has been thrown by the target of an invocation.
My code is:
private void runService()
{
string result = "";
string _uri = "net.tcp://localhost/netTcpService/NetTcpService.svc";
Uri uri = new Uri(_uri);
try
{
EndpointIdentity id = EndpointIdentity.CreateDnsIdentity("my-pc");
var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
binding.SendTimeout = TimeSpan.FromMilliseconds(10);
EndpointAddress address = new EndpointAddress(uri, id);
ChannelFactory<INetTcpService> channel = new ChannelFactory<INetTcpService>(binding, address);
channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
INetTcpService client = channel.CreateChannel();
result = client.InsertValueInTable();
}
catch (Exception ex)
{
result = ex.Message;
Debug.Log(ex.Message);
Debug.Log(ex.StackTrace);
Debug.Log(ex.TargetSite);
Debug.Log(ex.ToString());
}
Debug.Log("RESULT: " + result);
//
}
Error details are:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Operation is not supported.
at System.ServiceModel.Channels.SecurityChannelFactory`1[System.ServiceModel.Channels.IDuplexSessionChannel].OnCreateChannel (System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.ChannelFactoryBase`1[System.ServiceModel.Channels.IDuplexSessionChannel].CreateChannel (System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.TransactionChannelFactory`1[System.ServiceModel.Channels.IDuplexSessionChannel].OnCreateChannel (System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.ChannelFactoryBase`1[System.ServiceModel.Channels.IDuplexSessionChannel].CreateChannel (System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000eb] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115
at System.ServiceModel.ClientRuntimeChannel..ctor (System.ServiceModel.Dispatcher.ClientRuntime runtime, System.ServiceModel.Description.ContractDescription contract, TimeSpan openTimeout, TimeSpan closeTimeout, IChannel contextChannel, IChannelFactory factory, System.ServiceModel.Channels.MessageVersion messageVersion, System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00000] in <filename unknown>:0
at System.ServiceModel.ClientRuntimeChannel..ctor (System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.ChannelFactory channelFactory, System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00000] in <filename unknown>:0
at __clientproxy_INetTcpService..ctor (System.ServiceModel.Description.ServiceEndpoint , System.ServiceModel.ChannelFactory , System.ServiceModel.EndpointAddress , System.Uri ) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[],System.Exception&)
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00119] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:513
--- End of inner exception stack trace ---
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0012c] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:519
at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:528
at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x001b8] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Activator.cs:338
at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Activator.cs:268
at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Activator.cs:263
at System.ServiceModel.ChannelFactory`1[NetTcpTestScript+INetTcpService].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) [0x00000] in <filename unknown>:0
at System.ServiceModel.ChannelFactory`1[NetTcpTestScript+INetTcpService].CreateChannel (System.ServiceModel.EndpointAddress address) [0x00000] in <filename unknown>:0
at System.ServiceModel.ChannelFactory`1[NetTcpTestScript+INetTcpService].CreateChannel () [0x00000] in <filename unknown>:0
In assets I added System.ServiceModel.dll. above service get call from normal windows form application. Service with wshttpbinding(transport security mode) works in unity3d. How can i consume netTcpBinding base service in unity3d..
Comment
Best Answer
Answer by ttesla · Dec 09, 2016 at 12:08 PM
I'm trying to achieve the same. I guess DuplexSession is not supported in Unity mono.
If we kept security mode none than it works. But with security it not support......