I have WCF service with wsDualHttpBinding.
How to host it in managed application?
Uri baseAddress = new Uri("http://localhost:51160");
using (ServiceHost host = new ServiceHost(typeof(FileServer), baseAddress))
{
host.Open();
Console.ReadLine();
host.Close();
}
The solution was to add endpoint to my service:
Uri baseAddress = new Uri("http://localhost:51160");
WSDualHttpBinding binding = new WSDualHttpBinding();
using (ServiceHost host = new ServiceHost(typeof(FileServer), baseAddress))
{
host.AddServiceEndpoint(typeof(IFileServer), binding, "http://localhost:51160/FileServer");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Open();
Console.ReadLine();
host.Close();
}
And the same thing on server side (in config)
<services>
<service name="AK3_Server.FileServer" behaviorConfiguration="FileServerBehavior">
<endpoint address="http://localhost:51160/FileServer" binding="wsDualHttpBinding"
bindingConfiguration="" contract="AK3_Server.IFileServer" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="FileServerBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
Related
When I start a new HttpBasicBinding to a web service which is not initiated yet, because the app pool is not started will result in an Internal Server Error 500. But when I start the Web Service from the browser the service is being started.
How can I start the web service before sending a new request?
Below my code:
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.Name = "AXDocumentBinding";
EndpointAddress address = new EndpointAddress(serviceUrl);
AA_DynamicsAXDocuHandlingClient cls = new AA_DynamicsAXDocuHandlingClient(binding, address);
cls.ClientCredentials.Windows.ClientCredential = new NetworkCredential(username, password, domain);
string retVal = cls.loadDocumentStr(AreaId, documentFileName, documentIdentification1, documentIdentification2, documentIdentification3, documentIdentification4, documentIdentification5, documentTable);
Thanks in advance
I've got a windows service, that hosts WCF service inside.
Below is definition of how endpoint is initialized:
WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
string url = ConfigurationManager.AppSettings["serviceUrl"];
Uri baseAddress = new Uri(url);
Uri metadataAddress = new Uri(url + "Description");
CallService service = new CallService(controller);
ServiceHost host = new WebServiceHost(service);
host.AddServiceEndpoint(typeof (ICallService), binding, baseAddress);
host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups;
ServiceDebugBehavior stp = host.Description.Behaviors.Find<ServiceDebugBehavior>();
stp.HttpHelpPageEnabled = true;
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
smb.HttpGetUrl = metadataAddress;
host.Description.Behaviors.Add(smb);
host.Open();
The problem is that when accesing this WCF service using computer name (e.g http://mycomputer.mydomain.int:4544/Somthing) first I receive an authentication window, and after it HTTP:400.
Everything works fine if accessing service using http://localhost:4544/Something, or if switch off Windows Authentication.
What is wrong with it?
I know that this error is very common, but I tried to apply the solutions to this problem and could not solve it.
Thats my code:
var endpoint = new EndpointAddress(new Uri("http://www3prz.bancobonsucesso.com.br/Servicos/app.svc"), EndpointIdentity.CreateDnsIdentity("bancobonsucesso.com.br"));
var binding = new WSHttpBinding();
binding.UseDefaultWebProxy = true;
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Message.EstablishSecurityContext = true;
binding.Security.Message.NegotiateServiceCredential = true;
var customBinding = new CustomBinding(binding);
SymmetricSecurityBindingElement security = customBinding.Elements.Find<SymmetricSecurityBindingElement>();
security.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
security.LocalClientSettings.DetectReplays = false;
SecureConversationSecurityTokenParameters secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
SecurityBindingElement bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
bootstrap.LocalClientSettings.DetectReplays = false;
ws = new ServicoClient(customBinding, endpoint);
ws.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ws.ClientCredentials.UserName.UserName = "test";
ws.ClientCredentials.UserName.Password = "test";
var return = ws.EmitirBoleto("test");
IN the WCF Binding use useDefaultWebProxy:
<bindings>
<basicHttpBinding>
<binding name="bindingName" useDefaultWebProxy="true">
WebProxy wproxy = new WebProxy("new proxy",true);
wproxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = wproxy;
This error may arise problem with proxy settings.
Please check Proxy setting with your web browser. Just changed connection settings Option -> settings -> connection settings to Auto detect proxy settings
Good luck ...
I have a class TestService which implements two service contracts called IService1 and IService2. But I'm facing a difficulty in implementation.
My code looks as follows:
Uri baseAddress = new Uri("http://localhost:8000/ServiceModel/Service");
Uri baseAddress1 = new Uri("http://localhost:8080/ServiceModel/Service1");
ServiceHost selfHost = new ServiceHost(typeof(TestService));
selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), baseAddress);
selfHost.AddServiceEndpoint(typeof(IService2), new WSHttpBinding(), baseAddress1);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();
I'm getting a run time error as:
The HttpGetEnabled property of
ServiceMetadataBehavior is set to true
and the HttpGetUrl property is a
relative address, but there is no http
base address. Either supply an http
base address or set HttpGetUrl to an
absolute address.
What can I do about it? Do I really need two separate endpoints?
you can fix it in two ways
1)
Uri baseAddress = new Uri("http://localhost:8000/ServiceModel");
ServiceHost selfHost = new ServiceHost(typeof(TestService), baseAdress);
selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), "Service");
selfHost.AddServiceEndpoint(typeof(IService2), new WSHttpBinding(), "Service1");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
2)
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri("http://localhost:8000/ServiceModel");
selfHost.Description.Behaviors.Add(smb);
All you need to do is to add an base address.
you still have two separated endpoints.
ServiceHost selfHost = new ServiceHost(typeof(TestService), new Uri ("http://localhost:8080/ServiceModel"));
To do the above using the config file I would do:
<endpoint
address="...."
binding="netTcpBinding"
bindingConfiguration="MyBinding"
contract="IService1">
<identity>
<servicePrincipalName value="name"/>
</identity>
</endpoint>
But how do I add it to the below code?
Uri uri = new Uri("http://example.com/service");
ServiceHost host = new ServiceHost(typeof(Service1), uri);
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
host.AddServiceEndpoint(typeof(IService1), binding, uri);
host.Open();
It's a bit cumbersome, you need to use the return value of the AddServiceEndpoint method and set it there:
ServiceEndpoint serviceEndpoint = host.AddServiceEndpoint(typeof(IService1), binding, uri);
EndpointAddress myEndpointAddress = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity("YourIdentity"));
serviceEndpoint.Address = myEndpointAddress;