Multiple endpoints under IIS - c#

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.

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.

c# - trying to build a web service client from WSDL but no config file is provided

I'm just getting familiar with WCF and I have to add additional functionality to a working web service at work. As I feel the need to be able to test the functionality before deploying it, I decided to build a test client. Here comes the problem.
I created a Console Application just for the purpose of a test client and tried to add a Service Reference through the provided WSDL but it didn't work. There was no config file created.. I tried first the "Add Service Reference" option in VS and when it didn't work, I tried creating the Proxy and Config files with svcutil.exe...
Just the proxy class gets created... When I try to instantiate a "client object" from that class, the following Exception is thrown: "Could not find default endpoint element that references contract 'eOrderingService.IeOrderingService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."
As this is a working service (a Czech company is using it), apparently there must be a way to create a web.config or app.config even manually but I have no idea where to start.. As I said I'm just getting familiar with WCF so I started looking online but most of the problems connected somehow to my issue were in different parts of the already created Config files.. I managed to bypass that exception adding the following to app.config:
<system.serviceModel>
<services>
<service name="eOrderingService" >
<endpoint
address="http://localhost:61472/eOrderingService.svc"
binding="webHttpBinding"
contract="eOrderingService.IeOrderingService" >
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint
address="http://localhost:61472/eOrderingService.svc"
binding="webHttpBinding"
bindingConfiguration=""
contract="eOrderingService.IeOrderingService"
behaviorConfiguration="web"
name="DeliveryNote" >
</endpoint>
</client>
The service has a lot of methods and the one I need to test is called 'DeliveryNote'.
So lets say the service is at this address:
http://localhost:61472/eOrderingService.svc
The POST method I need to call is:
http://localhost:61472/eOrderingService.svc/DeliveryNote
And respectively the GET method is:
http://localhost:61472/eOrderingService.svc/DeliveryNote?DocumentFilter={DOCUMENTFILTER}&CustomerID={CUSTOMERID}&FromDate={FROMDATE}
The links are working but I cannot figure out how to call them from the client.
When I tested calling the POST method I received another exception:
The remote server returned an unexpected response: (400) Bad Request.
That shouldn't be true because the request I'm sending is already tested and is a valid request in XML format.
So I tried to test with a different GET method that works and receives just two DateTime parameters and not a Xml. If I try the following link:
http://localhost:61472/eOrderingService.svc/PriceChanges?startDate=2018-08-29&endDate=2018-08-30
the result is OK..
But if I call the automatically generated method "PriceChanges" the result is NULL.
I just don't get what I do wrong. It seems like a connection to the service is established but the methods are not called/build correctly. Probably because I cannot comprehend how to build the <system.serviceModel> in app.config.
I definitely should read more about the web services but I don't know where to start.

relationship between configuration in app.config or web.config and code in WCF

How does a service host in WCF interact with the configuration from the web.config or app.config. When I create a service host I only specify an url in the service host constructor and the class of the service.
But in the app.config or web.config I have another list of endpoints, each with it's own specific url. So how does wcf handle this situation? Which endpoint does it take from the app.config or web.config?
The address of the endpoint is relative to the base address of the service host. For example, if you had these endpoints:
<service name="MyService">
<endpoint address="" binding="ws2007HttpBinding" contract="IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
and a service host url of http://localhost:7777, then you would be exposing your service on http://localhost:7777, and the metadata on http://localhost:7777/mex.
So in general your interaction depends on several factors - your hosing environment, you code and your web or app settings.
According to MSDN (http://msdn.microsoft.com/en-us/library/ms733749.aspx): There are two ways to specify endpoint addresses for a service in WCF. You can specify an absolute address for each endpoint associated with the service or you can provide a base address for the ServiceHost of a service and then specify an address for each endpoint associated with this service that is defined relative to this base address. You can use each of these procedures to specify the endpoint addresses for a service in either configuration or code. If you do not specify a relative address, the service uses the base address.
Also you must pay attention on your hosting environment. For example IIS itself generates your base adress for endpoint (even if it is specified in config), meanwhile in self-hosts read it from configuration.
The above link greatly describes the features of specifing your adress in code or configuration, and its dependance on your host environment

Simple Wcf service result in no endpoint exception

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.

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.

Categories