WCF failing when service is impleneted over HTTP AND HTTPS - wcf

<system.serviceModel>
<services>
<service name="foo">
<endpoint address="" behaviorConfiguration="testbehaviour" binding="webHttpBinding" contract="testcontact" bindingConfiguration="webBinding" />
<endpoint address="" behaviorConfiguration="testbehaviour" binding="webHttpBinding" contract="testcontact" bindingConfiguration="webBindingHttps" />
</service>
</services>
<system.serviceModel>
As shown in the the web.config extract above, on our windows server 2008 machines, we had one endpoint that could be reached over HTTP and HTTPS.
I have just done an install of server 2012 (with iis8), and I now get the message
"Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http]."
The very odd thing is - if I comment one endpoint element out (leaving just one active endpoint left), then the remaining endpoint will work fine?

I had set the site up in IIS wrongly - I had created a separate website for the HTTP version and one for the HTTPS version, when infact they should be the same website, but with HTTPS and HTTP bindings

Related

Endpoint tag order in web.config hosting WCF service in IIS

I host a WCF service in IIS and want to expose multiple endpoints (with different enpoint behaviours). The base address is determined by the IIS virtual directory and the .svc file name as I understand. I use the address attribute on the endpoints to distinguish them. For one endpoint I leave the address blank, because this is the default endpoint that is already in use by applications. On the other endpoint I set an address.
Is it possible that the order of endpoint tags in the config file does matter?
For the first configuration always the endpoint with the blank address kicks in, no matter it is addressed from the client with /Test or not:
<endpoint binding="basicHttpBinding" bindingConfiguration="myBindingCfg" contract="myContract" address="" behaviorConfiguration="myBehaviorCfg" />
<endpoint binding="basicHttpBinding" bindingConfiguration="myBindingCfg" contract="myContract" address="Test" />
For the second configuration everything works fine:
<endpoint binding="basicHttpBinding" bindingConfiguration="myBindingCfg" contract="myContract" address="Test" />
<endpoint binding="basicHttpBinding" bindingConfiguration="myBindingCfg" contract="myContract" address="" behaviorConfiguration="myBehaviorCfg" />

Unable to configure WCF service for net.tcp in IIS hosting multiple sites

Trying to set up second web site in IIS 7, most/all of the mirrored services function except ones configured for net.tcp. Trying to access the .svc url, I receive the following error:
Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
IIS binding configuration:
Advanced Settings:
Trying to follow answers found on Stack Overflow, none seem to work.
Content of the service's web.config:
<system.serviceModel>
<services>
<service name="ServiceName">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
name="basic" contract="ServiceName.IService" />
<endpoint address="nettcp" binding="netTcpBinding" bindingConfiguration=""
name="netTCP" contract="ServiceName.IService" />
<host>
<baseAddresses>
<add baseAddress="http://staging.localhost/ServiceName" />
<add baseAddress="net.tcp://localhost:8033/ServiceName" />
</baseAddresses>
</host>
</service>
</services>
Is there a trick to the net.tcp bindings? What is correct configuration needed in the web.config?
Thanks!
A screenshot is worth a 1,000 words sometimes. In IIS manager, right-click on the application "ServiceName" and select Manage Application->Advanced Settings. In the advanced settings dialog box, check to see if you've added net.tcp to the Enabled Protocols:

wcf endpoint relative address

I'm just learning wcf and can't understand one very basic thing.
I'm creating a WCF service which I want to be hosted in IIS just like web application with it's own path like http://myhost/myapp/ and everything.
I'm creating the WCF service project in VS, I've got an *.svc file describing it, then I define a simple endpoint to it like that:
<endpoint address=""
binding="basicHttpBinding"
contract="wcf_service_auth.IPshService" />
Then I publish this service like an IIS web application to a virtual directory, let's assume it's name psh_pub, so I can access the service via url http://localhost/psh_pub/pshservice.svc/. It shows me WCF greetings page and gives me a link to WSDL, which gives me correct wsdl description.
That's ok.
The next step - I want to add a MEX endpoint. I add to config:
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
That's ok too, the endpoint is accessible at address http://localhost/psh_pub/pshservice.svc/mex and WcfTestClient.exe gives me correct config from that url.
Here the problem comes.
I have a WCF service working under IIS and I want to add one more endpoint to it. For example let it be a net.tcp endpoint. The IIS is configured by default to accept net.tcp connections at port 808 and I'm adding net.tcp protocol to properties of my web app, and I want to add an endpoint to my service like that:
<endpoint address=""
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
and now I assume that my service should be accessible via the url net.tcp://localhost:808/psh_pub/pshservice.svc. But it's not. And every "how-to" and manual on the web tells that I should specify full address in the config file like that:
<endpoint address="net.tcp://localhost:808/psh_pub/pshservice.svc"
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
And if I do so, it works. But if host the service in another virtual directory, I'll need to change the config. If I host it on the other server, I'll need to change config. If I host it on multiple servers, I'll have to maintain as many configs as servers I have.
So the main questions is:
Is there any way in WCF to specify a net.tcp (or https) endpoint of a IIS-hosted WCF service without specifying absolute url for it?
You should be able to define a base address for your net.tcp service endpoints:
<service name="YourServiceName">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:808/psh_pub/" />
</baseAddresses>
</host>
Then you should be able to use relative addresses in your actual endpoints:
<endpoint name="Tcp01"
address="pshservice.svc"
binding="netTcpBinding"
contract="wcf_service_auth.IPshService" />
</service>
WCF file-less activation (.Net 4.0) will let you register under a relative virtual path using the relativeAddress attribute:
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="relative-virtual-path/yourservice.svc"
service="YourServiceImpl" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
relative to the base address of the Web application
This link talks about it: http://msdn.microsoft.com/en-us/library/ee354381.aspx

WCF Basics - Endpoints

I'm wondering about the address="" section in the web.config file
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" name="user">
<endpoint address="" behaviorConfiguration="ptUserAspNetAjaxBehavior" binding="webHttpBinding" contract="IUser" />
</service>
</services>
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" name="controller">
<endpoint address="" behaviorConfiguration="ptUserAspNetAjaxBehavior" binding="webHttpBinding" contract="Icontroller" />
</service>
</services>
I'm adding a second service that I will be calling via jQuery. My first service worked great. As you can see the endpoint address is blank. I'm adding the second service and I'm wondering first if I'm doing it correctly? Can I create a new service tag using the same behaviorConfiguration, and binding but with a different contract?
This spawned another question about the address in the web.config file.
Why does it work when it is = "" and why would I want to use an address?
It will work with address="" when
you host your service in IIS and basically IIS's virtual directory dictates the URL of your service (the vdir where your *.svc file exists). Thus if you have two separate services, with two separate *.svc files, then each entry in the configuration can have an address="" setting. But you cannot have two endpoints for the same service and both have the empty address attribute
or:
you have a base address defined for your service in your config and thus that endpoint will use that base address for its service address

WCF wsHttpBinding and BasicHttpBinding in same WCF Service Application

I have been told that wsHttpBinding does not support older clients that still need to use older version of SOAP. I want to add a BasicHttpBinding endpoint in the same WCF Service Application so that clients can use either endpoint depending on their technology they are running. I am confused as to what the address to use for each of them. The default wsHttpBinding has no address set. What should the address be for BasicHttpBinding endpoint? Shouldn't the address for the wsHttpBinding be (for my example) http://localhost/WcfService1/Service1.svc ?
There's two things you need to consider here:
if your hosting in IIS (or WAS as part of IIS7), you cannot set a base address - the base address for your service will be the virtual directory where the MyService.svc file lives. You can still set relative addresses, though
if you self-host, you typically will add base addresses in your config, so you can spare yourself having to spell out the entire address all the time (but you can - if you wish to do so).
So if you have your MyService.svc inside a virtual directory called MyApp on your localhost machine, and then use this config:
<service name="MyService" behaviorConfiguration="Default">
<endpoint
address="wsHttp"
binding="wsHttpBinding"
contract="IMyService" />
<endpoint
address="basic"
binding="basicHttpBinding"
contract="IMyService" />
</service>
then your "old-style" basicHttp service will be reachable at:
http://localhost/MyApp/MyService.svc/basic
and your new wsHttp driven service will be reachable at:
http://localhost/MyApp/MyService.svc/wsHttp
You can name those relative addresses (anything after .../MyApp/MyService.svc) anything you like - just make sure they're different from one another.
Hosting in IIS --> location (virtual directory) of your *.svc file becomes your base address.
If you self-host your service inside a console app or a Windows NT Service, you get to set your base addresses yourself:
<services>
<service name="MyService" behaviorConfiguration="Default">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8185/Services/" />
</baseAddresses>
</host>
</service>
</services>
Now in this case, your "old-style" basicHttp service will be reachable at:
http://localhost:8185/Services/basic
and your new wsHttp driven service will be reachable at:
http://localhost:8185/Services/wsHttp
You can define a base address for each of the transports, e.g. one for http://, one for net.tcp:// and so on.
And of course, if you really must, you can also define your complete addresses inside your <endpoint> element for each of the service endpoints - this gives you total flexibility (but only works in self-hosting scenarios).
Marc
In WCF you have a base address and an enpoint address, in your case you can do something like this:
<service name="WcfEndpoints.Service1" behaviorConfiguration="WcfEndpoints.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="new" binding="wsHttpBinding" contract="WcfEndpoints.IService1" />
<endpoint address="old" binding="basicHttpBinding" contract="WcfEndpoints.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
Note you will need additional work for the basicHttpBinding endpoint to work with older (asmx) clients
http://msdn.microsoft.com/en-us/library/ms751433.aspx