I have a wcf project and I'm creating a client to test it. For some reasons, on my local machine I can run the service only within IIS Express from visual studio. After I start the project, I'm trying to connect to the service from a client, but I'm getting an error:
You have tried to create a channel to a service that does not support
.Net Framing. It is possible that you are encountering an HTTP
endpoint.
I've read this and this but they're discussing about IIS and not IIS Express.
Here is my code from the client:
NetTcpBinding binding = new NetTcpBinding();
EndpointAddress address = new EndpointAddress("net.tcp://localhost:64255/MyService.svc");
ChannelFactory<IMyInterface> channelFactory = new ChannelFactory<IMyInterface>(binding, address);
channelFactory.Open();
IMyInterface _clientProxy = channelFactory.CreateChannel();
((IClientChannel)_clientProxy).Open();
And when I'm calling the method Open, I'm getting the error above...
Please note that the service accepts only net.tcp protocol.
What do I need to change to call this service hosted in IIS Express from my client?
Edit: when I'm running the project from visual Studio, in the browser I'm seeing the url: http://localhost:64255/MyService.svc
Long story short: IIS Express does not support non-HTTP protocols such as net.tcp. IIS Express only supports HTTP and HTTPS as its protocol
Related
There is an issue for connecting to my WCF service from dotnet core 3.1 . For adding service reference I'm using Add Connected Service and then enters WCF URI http://10.10.10.10:8330/mywcfservice. If I enter the remote address as I said before it works fine and server asks for authenticate my request. but after I entered my credentials, in status box it said:
An error occurred while attempting to find services at '10.10.10.10/mywcfservice'. The remote server returned an error:(400) Bad Requst.
If I add / after WCF URI, in status box it said:
An error occurred while attempting to find services at '10.10.10.10/mywcfservice/'. The remote server returned an error:(401) Unauthorized.
I tested my WCF Service with WCF Storm and it works just fine. On the other hand I can connect to WCF Service from .Net Standard Project like a charm. So where is the problem?
Based on the information you provided, I cannot know what happened to your server. You can refer to this link to record the error that occurred on the server-side:
Trying to add a service reference results in Bad Request (400) in one project, otherwise runs fine
Another solution is to use dotnet-svcutil command:
Use a browser to access the WSDL file of the service, and then save it locally.
Then use the dotnet-svcutil command to generate the proxy class.
Finally, add the proxy class to the project.
To use the proxy class also need to add these two packages:
Call WCF service in core:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8000/GettingStarted/CalculatorService");
CalculatorClient calculatorClient = new CalculatorClient(binding,endpointAddress);
Another thing to note is that there are some WCF functions that are not supported in core. For details, please refer to the link below:
WCF service works in MVC client but not in .Net Core 3 client
Feel free to let me know if the problem persists.
I wrote a C# console application to consume a local WCF service using NetNamedPipeBinding. The WCF service I consume is running as a local Windows application. My WCF client works fine as a console application. However, when I implement essentially the same WCF client not as a console application but as a Windows service, my WCF client cannot find the local WCF endpoint and throws System.ServiceModel.EndpointNotFoundException exceptions.
Why would a WCF client run fine as a console application and then throw EndpointNotFoundException when the client is running as a Windows service?
This is how I create the channel factory in the client code:
// Define some local variables needed to create the channel factory
string strendpoint = string.Format("net.pipe://localhost/{0}", BluehillAPIService.ServiceName);
EndpointAddress endpoint = new EndpointAddress(strendpoint);
NetNamedPipeBinding binding = new NetNamedPipeBinding();
InstanceContext instanceContact = new InstanceContext(this);
// Create the channel factory
ChannelFactory = new DuplexChannelFactory<IBluehillAPIService>(instanceContact, binding, endpoint);
Then I create the channel like this:
_bluehillAPIService = ChannelFactory.CreateChannel();
No errors so far, but when I try to actually use the channel as follows, I get an exception:
if (!_bluehillAPIService.APIHeartbeat()) ...
The call to _bluehillAPIService.APIHeartbeat() in my WCF client generates a System.ServiceModel.EndpointNotFoundException when this code is running as a Windows service logged in as Local System but works fine when essentially identical code is running as a console application.
Because the LocalSystem account presents anonymous credentials when accessing network resources, network applications running in that context may not operate as expected.
Specify an appropriate account on your service's "Log On" tab -- an account where you can log in and run the application without error:
Trying to implement https on a WCF webservice which we are not running in IIS. Currently using the following code for each class and interface which describes and implements a service.
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
WebServiceHost host = new WebServiceHost(typeof(ServiceClass), "https://localhost:8085/ServiceClass");
host.AddServiceEndpoint(typeof(IServiceClass), binding, "");
host.Open();
The service starts without any exceptions, but when I try to connect a browser to :
https://localhost:8085/ServiceClass/Item?format=xml
I get a ERR_CONNECTION_RESET error. Additionally I hook host.Faulted and host.Closed and am not getting any error messages.
I can't find an example anywhere of implementing WCF web service over https using basic authentication, which is what we're looking for.
I am running a self-hosted WCF service. In the service configuration, I am using localhost in my BaseAddresses that I hook my endpoints to. When trying to connect to an endpoint using the WCF test client, I have no problem connecting to the endpoint and getting the metadata using the machine's name. The problem that I run into is that the client that is generated from metadata uses localhost in the endpoint URLs it wants to connect to. I'm assuming that this is because localhost is the endpoint URL published by metadata. As a result, any calls to the methods on the service will fail since localhost on the calling machine isn't running the service.
What I would like to figure out is if it is possible for the service metadata to publish the proper URL to a client depending on the client who is calling it. For example, if I was requesting the service metadata from a machine on the same network as the server the endpoint should be net.tcp://MYSERVER:1234/MyEndpoint. If I was requesting it from a machine outside the network, the URL should be net.tcp://MYSERVER.mydomain.com:1234/MyEndpoint. And obviously if the client was on the same machine, THEN the URL could be net.tcp://localhost:1234/MyEndpoint.
Is this just a flaw in the default IMetadataExchange contract? Is there some reason the metadata needs to publish the information in a non-contextual way? Is there another way I should be configuring my BaseAddresses in order to get the functionality I want?
Thanks,
Mike
What .NET version are you using? If you're using .NET 4.0, add the UseRequestHeadersForMetadataAddressBehavior to your service host:
UseRequestHeadersForMetadataAddressBehavior urh =
new UseRequestHeadersForMetadataAddressBehavior();
serviceHost.Description.Behaviors.Add(urh);
Obviously, this needs to be done prior to opening the service host.
If you're using .NET 3.5, there's a hotfix that adds this behavior: support.microsoft.com/kb/971842.
I wrote the WCF Service and hosted in windows service. I need to know how to consume this windows service in my client application.
Note:
I wrote Net pipe binding service.
Edit:
How can I write the client application for net pipe binding?
You need to do a few easy steps:
start your Windows service hosting your WCF service
from within Visual Studio (2008 or higher), right-click on a project node in the solution explorer and choose "Add service reference"
enter the URL where your service can be reached
That's about all there is, really. Visual Studio will go to your running service, get all the metadata it needs (assuming you've enabled a MEX endpoint for metadata exchange), and will create a client proxy class for you to use to connect your client to your service.
Marc
you need to use ChannelFactory to create a proxy, and then you can use the proxy to perform wcf tasks.
ChannelFactory<IWCFService> pipeFactory = new ChannelFactory<IWCFService>(
new NetNamedPipeBinding(),
new EndpointAddress("net.pipe://localhost/PipeWCFService"));
IWCFService pipeProxy = pipeFactory.CreateChannel();
pipeProxy.RunWCFServiceMethod();}
http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication
You can consume it like any other WCF service. The method used for hosting the WCF service is not relevant to the client side.
If you need details on how to actually build the client, let me know and i'll update the post.
Edit : Start here to learn how to build a WCF client.