Configuration of UDPbinding in Universal App framework - wcf

I am migrating an "old" code from Framework 4.6 to universal app code to consume a WCF Service.I have different bindings, NetTCPbinding is working ok, when configuring my binding for consuming an UDPbinding from WCF in 4.6 framework I cannot find UDPbinding in System.ServiceModel anymore in .NET for Universal Apps.
I need a communication as fast as possible and .nettcpbinding seems not enough.
I have added as reference System.ServiceModel and System.ServiceModel.Channels
Any idea?
This is my code from the client in .NETCORE for Universal for configuring the connection to WCF Service:
try
{
//Here I cannot find the UDPbinding!!!!!
UdpBinding myBinding = new UdpBinding();
EndpointAddress addr = new EndpointAddress("soap.udp://" + ipAddress + ":" + portNo);
ChannelFactory<IService1> chn = new ChannelFactory<IService1>(myBinding, addr);
IService1 conn = chn.CreateChannel();
return conn;
}
catch (Exception ex)
{
return null;
}
My server service configuration routine is this:
private void ConfigService(string portNo) {
host = new ServiceHost(typeof(WCFComm), new Uri("http://localhost:/XXX/XXX"));
// Add service endpoint
UdpBinding myBinding = new UdpBinding();
string address = "soap.udp://localhost:" + portNo;
host.AddServiceEndpoint(typeof(IService1), myBinding, address);
try {host.Open();} catch(Exception ex) {}
}
Thanks,

Sorry it is not supported only BasicHttp

Related

Fail to connect to WCF Service on my Localhost

I got the below error when trying to connect to WCF service running on my localhost using the WCF Test Client tool. I entered the end-point address as "net.tcp://localhost:19998/MyWCFService". MyWCFService is launched within Visual Studio 2017 on my local PC.
"There was no endpoint listening at net.tcp://localhost:19998/MyWCFService that
could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."
I can verify the port 19998 is listening on my PC using the netstat.
TCP 0.0.0.0:19998 LISTENING
I have disabled all the firewall on my PC.
It turns out that my WCF service has some runtime errors that prohibits any clients to connect to it.. I have fixed the errors and i can connect now. Thanks.
It seems that the error is caused by that the service address is wrong. How do you host the service on the server side? I would like you could post more details about the server side so that give you an effective reply.
Here is my example about using NetTCPBinding, wish it is useful to you.
Server
class Program
{
static void Main(string[] args)
{
Uri uri = new Uri("net.tcp://localhost:1500");
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
using (ServiceHost sh = new ServiceHost(typeof(Calculator), uri))
{
sh.AddServiceEndpoint(typeof(ICalculator), binding,"");
ServiceMetadataBehavior smb;
smb = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
{
smb = new ServiceMetadataBehavior();
//smb.HttpGetEnabled = true;
sh.Description.Behaviors.Add(smb);
}
Binding mexbinding = MetadataExchangeBindings.CreateMexTcpBinding();
sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "MEX");
sh.Open();
Console.Write("Service is ready....");
Console.ReadLine();
sh.Close();
}
}
}
[ServiceContract]
public interface ICalculator
{
[OperationContract]
int Test(int a);
}
public class Calculator : ICalculator
{
public int Test(int a)
{
return a * 2;
}
}
Result.
Feel free to let me know if there is anything I can help with.

CRM Dynamics 2015 Plugin registration Tool crashes on WCF/ASMX service call

Your help will be highly appreciated, I have registered a Plug-in on phone call create in CRM Dynamics 2015, When I debug the plugin using the profiler, the plugin Registration tool stops working as soon as I make a call to the WCF service client method exposed. I have tried with both an ASXM service and a WCF service,i have deployed the service in IIS on the same server CRM is hosted,I tested the service against a console and SOAP UI, everything works fine, the minute I use it kin a Plugin context it crashed the registration tool on service call. There is no error logged in the plugin Registration tool log files, here is my plugin code below
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context == null)
{
throw new ArgumentNullException("localContext");
}
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity phoneCallEntity = (Entity)context.InputParameters["Target"];
if (phoneCallEntity.LogicalName != "phonecall")
return;
//ensure that the Plugin fires on a create operaton
if (context.MessageName == "Create")
{
try
{
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = "BasicHttpBinding_IService1";
myBinding.Security.Mode = BasicHttpSecurityMode.None;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endPointAddress = new EndpointAddress("http://154.66.196.127/Webservice/ZoiperCallHistory.asmx");
ZoiperCallHistorySoapClient client = new ZoiperCallHistorySoapClient(myBinding,endPointAddress);
client.Open();
CallHistory callHistory = client.GetZoiperCallHistory();
client.GetZoiperCallHistory();
The code fails on this line : CallHistory callHistory = client.GetZoiperCallHistory();
Thanks in advance.
In my experience the plugin registration tool doesn't go well with debugging web service calls. Try instead using the tracing service to identify errors or to analyze the web service response.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));

Hosting WCF service on linux

Is there Any way of hosting WCF service on Linux.
I read about wine but i didn't see any example of hosting WCF service with it.
P.S : I have tried mono and mod_mono but to no avail.
You can host it in a stand-alone console application like so:
using System;
using System.ServiceModel;
using Service;
namespace Host
{
class MainClass
{
public static void Main (string[] args)
{
Console.WriteLine ("WCF Host!");
var binding = new BasicHttpBinding ();
var address = new Uri ("http://localhost:8080");
var host = new ServiceHost (typeof(GreeterWcfService));
host.AddServiceEndpoint (
typeof(IGreeterWcfService), binding, address);
host.Open ();
Console.WriteLine ("Type [Enter] to stop...");
Console.ReadLine ();
host.Close ();
}
}
}
Where GreeterWcfService is the WCF service class itself and IGreeterWcfService is the service contract.
Full working example solution in GitHub - with separate projects for the service, the hosting and a client. Check it out.
Its possible but you should refer to this link for understanding current state and known issues - http://www.mono-project.com/docs/web/wcf/. It's limited now. For eg. if you wish to use WSHttpBinding its not supported currently.

Programmatic TFS 2010 Event registration + error HTTP code 415: Cannot process the message because the content

i want to use tfs event registration for reading out the BuildQualityChanged and the WorkItemChanged event. It was working some month before, now i get the following error while getting the event xml:
HTTP code 415: Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'. ---> System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
Im building a console application which will later be an windows service. The code for for hosting the wcf service is the following:
private void HostWcfService()
{
D_("Hosting WCF service");
var serviceUri = new Uri(GetCorrectServiceAddress());
_host = new ServiceHost(typeof(BuildQualityChanged), new []{serviceUri});
AddBehaviors(_host);
SetBinding(_host, serviceUri);
_host.Open();
}
private static void AddBehaviors(ServiceHost service)
{
var smb = service.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
{
smb = new ServiceMetadataBehavior();
service.Description.Behaviors.Add(smb);
}
smb.HttpGetEnabled = true;
var sdb = service.Description.Behaviors.Find<ServiceDebugBehavior>();
if (sdb == null)
{
sdb = new ServiceDebugBehavior();
service.Description.Behaviors.Add(sdb);
}
sdb.IncludeExceptionDetailInFaults = true;
}
private void SetBinding(ServiceHost _host, Uri serviceUri)
{
// create and configure an MTOM encoder
var mtom =
new TextMessageEncodingBindingElement(
MessageVersion.Soap11, Encoding.UTF8);
// create a CustomBinding using MTOM encoder
CustomBinding binding = new CustomBinding();
binding.Elements.Add(mtom);
binding.Elements.Add(
new HttpTransportBindingElement());
_host.AddServiceEndpoint(typeof(TFS.Build.ITeamFoundationEventSubscriber),
binding, serviceUri);
}
All solutions i found until now with this error does configuring the service in web.config, this is no possible solution for me, i have to host programmatically. The second solution i found is to use BasicHttpBinding rather than CustomBinding, but this does not work too for me, the tfs breaks with the same error. I was wondering that the SOAP Version in the WSDL by using BasicHttpBinding is SOAP 1.2 too. SetBinding() for using BasicHttpBinding is
var binding1 = new BasicHttpBinding();
binding1.Name = "binding1";
binding1.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding1.Security.Mode = BasicHttpSecurityMode.None;
_host.AddServiceEndpoint(typeof(TFS.Build.ITeamFoundationEventSubscriber), binding1, serviceUri);
The only difference in required and given request is the content type, i need application/soap+xml rather than application/xml
Can anyone tell me where my brain is going wrong?
Michael
After hours of searching i did not found any solution. A geek of microsoft helps me to get it rid:
TFS2010 only supports wsHttpBinding without security
The content of my SetBinding() method is now the following:
var binding1 = new WSHttpBinding();
binding1.Name = "binding1";
binding1.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding1.Security.Mode = SecurityMode.None;
_host.AddServiceEndpoint(typeof(TFS.Build.ITeamFoundationEventSubscriber), binding1, GetCorrectServiceAddress());
MAGIC, IT WORKS :)

How can I configure a webservice in .NET 4 without using app.config

I have a .NET 4 project made of a EXE project and a class library. The class library contains a reference to a webservice (using WCF).
Everything works ok only if I have deployed the app.config file (that contains the info about the binding) along with my exe. How can I have everything configured by code without the need to deploy an app.config file (I don't want my users to change those settings).
Thank you.
Andrea
You can use the ChannelFactory class to generate proxies to your services.
Everything you configure through the configuration file can also be done using code.
You just need to instantiate an instance of the correct binding and configure its properties according to the service requirements on the other side.
For example:
private IDisposableService GetClient()
{
var netBinding = new BasicHttpBinding();
netBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
netBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
var factory = new ChannelFactory<IDisposableService>(netBinding, new EndpointAddress(new Uri(ServerUrl)));
factory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
var channel = factory.CreateChannel();
return channel;
}
interface IDisposableService : IYourService, IDisposable
{
}
Then you can simply use:
using (var proxy = GetClient())
{
// call proxy here
}
This is how I did it:
MyServiceResponseClient embEvalServiceClient = new MyServiceResponseClient (new BasicHttpBinding(),
new EndpointAddress(new Uri(url)));
if (embEvalServiceClient != null)
{
embEvalServiceClient.GetPendingEvalsCompleted += getPendingEvalsCompletedHandler;
embEvalServiceClient.GetPendingEvalsAsync(attemptId);
}