Simple Wcf service result in no endpoint exception - c#

I am just learning wcf and I tried creating a WCF service but I keep getting this exception:
Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no
endpoint listening at http://localhost:8733/Person/ that could accept the messa
ge. This is often caused by an incorrect address or SOAP action. See InnerExcept
ion, if present, for more details. ---> System.Net.WebException: Unable to conne
ct to the remote server ---> System.Net.Sockets.SocketException: No connection c
ould be made because the target machine actively refused it 127.0.0.1:8733
I started out by creating a WCF Service Library.I have defined my service contract and data Contract here.And configured the endpoint witch look like this:
<service name="SelfHosting.PersonContract">
<endpoint address="" binding="basicHttpBinding" contract="SelfHosting.IPersonContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Person/" />
</baseAddresses>
</host>
</service>
These two endpoints were already added I just configured them to my needs.I am not sure what the mex endpoint is used for so I am hopping someone can tell me.
I then created a console application and I added a reference to the service.I have initialized an instance of the service and then I tryed calling it:
static PersonContractClient client = new PersonContractClient();
static void Main(string[] args)
{
var persons = client.GetPersons();
foreach (var personData in persons)
{
Console.WriteLine(personData.Name);
Console.WriteLine(personData.Email);
}
}
I have not set any endpoints on the client because from what I know they are automaticly added when you add a reference to the service.This was added after I adde the reference:
<endpoint address="http://localhost:8733/Person/" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IPersonContract" contract="PersonNamespace.IPersonContract"
name="BasicHttpBinding_IPersonContract" />
My solution also contains another project that has the data, which I get using Entity Framework. I do not know if this is relevant to the problem.
What am I doing wrong here?

I had similar problem when i tried to create a duplex wcf communication using self host in a console application. Following this example http://adamprescott.net/2012/08/15/a-simple-wcf-service-callback-example/ made it clear. It is common to get the error
"Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://localhost:8733/Person/ that could accept the messa ge. This is often caused by an incorrect address or SOAP action. See InnerExcept ion, if present, for more details. ---> System.Net.WebException: Unable to conne ct to the remote server ---> System.Net.Sockets.SocketException: No connection c ould be made because the target machine actively refused it 127.0.0.1:8733"
Before attempting to discover the service reference in the client console app, you need to start up the executable(.exe) of the service by right click the .exe in the folder location > copy the uri in the baseaddress in the service app.config and paste in the add service reference dialog then click ok... that fixed it. I hope this helps others, since the question is a bit old.

Instead of 'localhost' in the url use the ip address of the endpoint.

Related

WCF Endpoint connection fail

I'm using WCF to do IPC communication between two processes.
The settings below are the endpoint settings set on the server side.
<services>
<service name="IPC.Server.SessionService">
<endpoint address="net.pipe://localhost/TestSessionService" binding="netNamedPipeBinding" bindingConfiguration="" contract="IPC.ISessionService" />
</service>
</services>
And the settings below are the endpoint settings set on the client.
<client>
<endpoint address="net.pipe://localhost/TestSessionService" binding="netNamedPipeBinding" bindingConfiguration="" contract="IPC.ISessionService" name="SessionServiceClient" kind="" endpointConfiguration="" />
</client>
The problem is that if the server program is started with administrator privileges, IPC communication succeeds, but if it is started with normal user privileges, endpoint connection from the client fails.
The client program has normal privileges.
I googled for a while, but couldn't find any specific information.
I checked by leaving a debug log, and the server program succeeded in creating an endpoint even with normal privileges.
In other words, the problem is that the client cannot connect to the endpoint created with normal privileges.
Thank you for help.
PS) This is the error message from client (japanese and english)
<Message=メッセージを受信できる net.pipe://localhost/TestSessionService でリッスンしているエンドポイントがありませんでした。これは一般に、アドレスまたは SOAP アクションが正しくない場合に発生します。詳細については、InnerException を参照してください (ある場合)。>
<Message=There was no endpoint listening on net.pipe://localhost/TestSessionService that could receive messages. This generally happens when the address or SOAP action is incorrect. See InnerException for details, if any. >
As far as I know, administrative privileges are only needed for the HTTP URL namespace reservations. NetNamedPipeBinding does not require administrator privileges.
If not, try WSDualHttpBinding and allow the user to reach the common namespace.

WPF Client with WCF Service from Localhost dev to prod server?

I am just starting to learn WCF. I have successfully set up a WCF service with host console app. The service maps to SQL Server with Entity Framework. I then have a WPF client app which consumes the service. This all works fine in Dev, both the service and client app running from my machine:
<endpoint address="http://localhost:8081/" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IRegimesService" contract="RegimesService.IRegimesService"
name="BasicHttpBinding_IRegimesService" />
I have now transferred the service and host onto my new VM. The service host runs fine. I am now trying to configure the client app endpoint to connect to the service. I think the HTTP address is incorrect:
Service app.config:
<services>
<service name="diiRegimesService.RegimesService">
<endpoint address="" binding="basicHttpBinding" contract="diiRegimesService.IRegimesService"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8082" />
</baseAddresses>
</host>
</service>
</services>
Client app.config:
<client>
<endpoint address="http://emea-myserver01.emea.basketballinfo.com/localhost:8082/" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IRegimesService" contract="RegimesService.IRegimesService"
name="BasicHttpBinding_IRegimesService" />
</client>
The server credentials for remote desktop are: emea-myserver01.emea.basketballinfo.com
I currently don't specify a username & password in my client app.config.
The service is running on the server. I'm getting an exception trying to add the service reference in the client app.
Add Service Reference- Adress: http://EMEA-myserver01.emea.basketballinfo.com
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://emea-myserver01.emea.basketballinfo.com/'.
You need to make sure the server is able to resolve the full domain name.
Also, the address url provided in the client configuration snippet <endpoint address="http://emea-myserver01.emea.basketballinfo.com/localhost:8082/ does not seem valid. Perhaps you want to use <endpoint address="http://emea-myserver01.emea.basketballinfo.com:8082/

Hosting WCF on IIS - EndpointNotFoundException

After implemeting a WCF service, hosting it on the IIS Server, it returned with the below error.
EndpointNotFoundException was unhandled by user code There was no
endpoint listening at XXXXX that could accept the message. This is
often caused by an incorrect address or SOAP action. See
InnerException, if present, for more details.
That service is identically has the same implementation and configuration of 5 running services with no errors.
when I tried to figure out what is going on the IIS server, the below screenshot.
So it seems that this specific service has no detected Contract. although I'm using the same configuration as below.
<service name="XX.XX.Provisioning.EldaftarManagementService">
<endpoint address="" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" bindingNamespace="http://XX.XX.com/XX/" contract="XX.XX.Provisioning.Eldaftar.IEldaftarManagementService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="ProvisioningBasicBinding" bindingNamespace="http://XX.XX.com/provisioning/" contract="XX.XX.Provisioning.Eldaftar.IEldaftarManagementService" />
</service>
<service name="XX.XX.Provisioning.Common.UserManagement.UserManagementService">
<endpoint address="" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" bindingNamespace="http://XX.XX.com/XX/" contract="XX.XX.Provisioning.Common.UserManagement.IUserManagementService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="ProvisioningBasicBinding" bindingNamespace="http://XX.XX.com/provisioning/" contract="XX.XX.Provisioning.Common.UserManagement.IUserManagementService" />
</service>
Kindly noted that when accessing the service.svc url it replies normally and the wsdl is shown. So that means it's hosted fine on the IIS.
Do I miss something?
Update:
Client config.
<endpoint address="https://XXX/EldaftarManagementService.svc" behaviorConfiguration="ProvisioningClientBehaviour" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" contract="EldaftarManagementService.IEldaftarManagementService" />
<endpoint address="https://XXX/UserManagement.svc" behaviorConfiguration="ProvisioningClientBehaviour" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" contract="UserManagementService.IUserManagementService" />
i notice sometime after reconfigure my service reference, the client config getting wsdl with server name. then i get EndpointNotFoundException exception.
example :
service reference is : http://192.168.61.2:1111/Service1.svc
but in the config endpoint address it show : http://serverName:1111/Service1.svc
After i change the config endpoint address with the service reference address , then it resolved. Not sure why but now every time when i reconfigure the endpoint address, i will manually change the config endpoint address to make sure it get the same address.

Why do I have to add a reference to URL/service.svc but then it creates a binding for URL/service.svc/soap?

I am connecting a solution to a WCF SOAP based web service. The URL is in the format:
http://upload.pete.vls.com/api/hmlapi.svc
However when I add the reference the configuration comes up with the following:
<client>
<endpoint address="http://upload.pete.vls.com/api/HmlApi.svc/soap"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHmlApi"
contract="ServiceReference1.IHmlApi" name="BasicHttpBinding_IHmlApi" />
</client>
Im confused as to why when I add the reference with /soap/ on the end it doesnt work. But when I dont add it, the 'add reference' feature finds the service and adds it with a /soap/ anyway.
The URL you are entering (without the soap part) includes information on what types of service transport are offered. VS is choosing soap from that, and saving the proper endpoint address in the config.
That end URL would not be correct for what is being asked for when you are prompted, though. Because it's expecting a URL with information on the service - not the actual endpoint that will eventually get used.
Because your endpoint on the server is probably configured like that
<services>
<service name="YourService">
<endpoint name="mySOAPEndpoint" address="soap" binding="someHttpBinding" contract="IYourService" />
</service>
</services>
Note that the address is "soap" which is the relative path after your service URI (i.e. after the .svc). If you write address="" then your .svc URI is the same as your endpoint address.

Multiple endpoints under IIS

I have been trying to add a new endpoint in a service hosted under IIS but haven't been able to figure it out for the past day or so.
This is my understanding:
you can have multiple endpoints under IIS as long as they have unique addresses.
you could assign a base address but it will be overridden by the virtual directory setup in IIS.
My virtual directory is http://localhost/WcfCert/
<services>
<service name="WcfCertServer.Service1" behaviorConfiguration="WcfCertServer.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" contract="WcfCertServer.IService1"/>
<endpoint address="test" binding="wsHttpBinding" contract="WcfCertServer.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
I can bring up the service using http://localhost/wcfcert/service1.svc
but http://localhost/wcfcert/test/service1.svc/test doesn't return anything in IE or the client app
what am I missing here?
Edit:
So i did further testing, and here is what i discovered.
if i start WcfTestClient.exe and add either http://localhost:1523/Service1.svc or http://localhost:1523/Service1.svc/mex it will add both the endpoint under that address. so here is my question shouldn't http://localhost:1523/Service1.svc only represent the first endpoint? why adding that address bring up both endpoints?
but if I try to add http://localhost:1523/Service1.svc/test I get
Error: Cannot obtain Metadata from http://localhost:1523/Service1.svc/test If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:1523/Service1.svc/test Metadata contains a reference that cannot be resolved: 'http://localhost:1523/Service1.svc/test'. Sendera:BadContextTokenThe message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.HTTP GET Error URI: http://localhost:1523/Service1.svc/test There was an error downloading 'http://localhost:1523/Service1.svc/test'. The request failed with HTTP status 400: Bad Request.
It would actually be:
http://localhost/wcfcert/service1.svc/test
If you want the URL to be 'http://localhost/wcfcert/test/service1.svc', then you will need to specify the full URL in the address attribute.
I ran into a similar problem recently, and I believe the reason is because the WcfTestClient requires the mex endpoint to query the metadata for the service it is testing.
When you add the service address "http://localhost:1523/Service1.svc" to the WcfTestClient, it actually queries the endpoint "http://localhost:1523/Service1.svc/mex" to get the service description.
The error "Cannot obtain Metadata from "http://localhost:1523/Service1.svc/test" is displayed because the WcfTestClient is looking for the "/test/mex" endpoint to get the metadata for the service at "/test".
To fix this, you need to add another endpoint to provide metadata about the service hosted at address "/test":
<endpoint address="/test/mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
This is the solution that worked for me.

Categories