How can I change the URL of my WCF Service? - c#

I have this WCF Service:
http://localhost:56471/WcfPruebaService.svc
And I need it to be:
http://localhost:56471/ServiciosDePrueba/WcfPruebaService.svc

You just need to open app.config and replace the old address with the new one. Or if you want to change it in code (programmatically) you can use the following code:
WSHttpBinding binding = new WSHttpBinding();
EndpointAddress endpoint = new EndpointAddress(new Uri("***"));
MyServiceClient client = new MyServiceClient(binding, endpoint);
https://learn.microsoft.com/en-us/dotnet/framework/wcf/how-to-implement-a-wcf-contract#edit-appconfig
How to programmatically modify WCF app.config endpoint address setting?

Related

How to call wcf service with out added service reference using channel factory

Can any one help me on this.
"How to call wcf service with out added service reference using channel factory".
I have used this code :
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("");
ChannelFactory factory = new ChannelFactory<IUnityServiceChannel>(binding, address);
UnityServiceClient channel = new UnityServiceClient();
string token = channel.GetSecurityToken(svcUsername, svcPassword);
But I want to create the IUnityServiceChannel run time. I don't have any information about the IUnityServiceChannel.
So can you help me how to crate interface using reflection or some thing else.

WCF - Create client programmatically only from endpoint name

My WCF client can connect to several endpoints. But they all have different addresses, bindings and contracts. So my question is : How can I create my WCF client programmatically depending just of the name of my endpoint I want to connect to (which I have in my code)
If I understood your question correctly, I believe this is the answer [using IPC, can be easily converted to other communication types]
Listener:
_host = new ServiceHost(typeof(ContractClass));
_host.AddServiceEndpoint(typeof(IContract), new NetNamedPipeBinding(), new Uri("net.pipe://localhost/" + listenerEndpointName));
_host.Open();
Client:
var factory = new ChannelFactory<IContract>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/" + listenerEndpointName));
IContract proxy = factory.CreateChannel();

How to update client endpoint binding in code

I have a question about modifying client endpoint binding in code.
I have added a web service reference and created a client endpoint binding for it.
In web.config I a binding set to basic https, which I want to change it to ex. http, which I have specified in web.config under the name "basicHttpBinding". When I create the instance of the web service reference, there is no way of using address and binding as there is not constructor that takes such arguments.
<endpoint address="http://localhost/LocalService/SendRequest.asmx"
binding="basicHttpsBinding" bindingConfiguration="basicHttpsBinding"
contract="LocalService.SendRequest" name="LocalServiceClient" />
Any advice how to solve this problem would be appreciated.
Cheers!
var binding = new System.ServiceModel.BasicHttpBinding() { Name = "LocalServiceClient", Namespace = "LocalService.SendRequest" };
var endPoint = new System.ServiceModel.EndpointAddress("http://localhost/LocalService/SendRequest.asmx");
var client = new ServiceClient(binding, endPoint);
If I understood correctly, this is what you are looking for:
var x = new ServiceClient();
x.Endpoint.Binding = new BasicHttpBinding("optional configuration name");

WSDoAllReceiver: Incoming message does not contain required Security header

I have java service which communicates over https. I want to connect to this service from C#.
I am getting this exception:
System.ServiceModel.FaultException:
WSDoAllReceiver: Incoming message does
not contain required Security header.
Someone knows what is wrong?
C# Code:
EndpointAddress address = new EndpointAddress(
new Uri("https://JavaStore:8443/JavaStore/services/B2BService"),
EndpointIdentity.CreateDnsIdentity("JavaStore"),
new AddressHeaderCollection()
);
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
var client = new ReharB2BService.B2BServicePortTypeClient(binding, address);;
client.Open();
client.getAllItems();
Check this post on how to include security headers in WCF calls (the example is against a java hosted web service): http://isyourcode.blogspot.com/2010/05/using-oasis-username-token-profile-in.html

Using a C# Service Reference SOAP Client with different Endpoint URIs

I have a SOAP Webservice that is available on multiple servers, thus having multiple endpoints. I want to avoid adding multiple Service References (C# SOAP Port Clients) with different names just to talk to this services, since the API is exactly the same.
Is there a way to configure the Endpoint URI at runtime?
I use the following which works great:
ServiceReference1.wsSoapClient ws= new ServiceReference1.wsSoapClient();
ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://xxx/myservice.asmx");
I had trouble finding this one also. I finally just borrowed the configuration binding and did this:
private static wsXXXX.IwsXXXXClient wsXXXXClientByServer(string sServer)
{
// strangely, these two are equivalent
WSHttpBinding binding = new WSHttpBinding("WSHttpBinding_IwsXXXX");
// WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message, false);
EndpointAddress remoteAddress = new EndpointAddress(new Uri(string.Format("http://{0}:8732/wsXXXX/", sServer)), new UpnEndpointIdentity("PagingService#rl.gov"));
return new wsXXXX.IwsXXXXClient(binding, remoteAddress);
}

Categories

Resources