What kinds of non-HTTP addresses are allowed in WCF endpoints? - wcf

I'm just trying to save time by not learning about IIS and WAS, so I made a console application to host my WCF service. However, that leaves me uncertain as to how to specify an endpoint address that is not an HTTP address. Could the following config be the source of my runtime error? The exception description was: Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding. Registered base address schemes are [].
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<endpoint
contract="WcfService1.IService1"
binding="wsHttpBinding"
address="c:\users\owner\documents\visual studio 2010\projects\wcftest\wcfservice1\wcfservice1\service1.svc"/endpoint>
</service>
</services>

The word you're looking for is bindings. You change the binding attribute to match a binding that supports your desired protocol. For a simple console service host, I'd probably start with the netTcpBinding, which allows binding to an ipaddress:port combination.
Example:
net.tcp://localhost:8000/myservice

Related

How to expose a single WCF service with multiple service behaviours?

I have a WCF service which needs to meet the following requirement:
Endpoint1 : It should use netTCP binding with windows authentication.
Endpoint2 : It should use netTCP binding with Custom User name and password validation.
I was able to do both of these individually by creating two service behaviors, one for Windows authentication and one for user name and password, but this way I have to expose 2 service instead of 1 for the above functionality. I am looking for a way by which I could expose only one service and by different end point configuration, I am able to fulfill the requirement.
Code snippet and configuration would be helpful.
This is one of the scenarios that WCF supports, a single interface exposed as 2 different endpoints.
They will have two different addresses, but will point to the same code.
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<!-- This endpoint is exposed at the base address provided by host: http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- secure endpoint exposed at {base address}/secure: http://localhost/servicemodelsamples/service.svc/secure -->
<endpoint address="secure"
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
...
</service>
See: http://msdn.microsoft.com/en-us/library/ms751515.aspx

Absolute path is not working for WCF Service

I have a service file available in the following location.
C:\Documents and Settings\U16990\My Documents\Visual Studio 2010\Projects\CalculationService\CalculationService\CalculationService.svc
When I browse the svc file, it is working fine. The service endpoint is as listed below. It is currently a relative address used for address.
<service name="CalculationService.CalculationService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="CalculationService" behaviorConfiguration=""
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_CalculationServiceInterface"
contract="ICalculationService" />
</service>
IP address of my machine is 10.10.179.180 //InterNetwork AddressFamily
When I change the address to use absolute path it is throwing error:
<services>
<service name="CalculationService.CalculationService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint
address="http://10.10.179.180/C:/Documents and Settings/U16990/My Documents/Visual Studio 2010/Projects/CalculationService/CalculationService/CalculationService.svc/CalculationService"
behaviorConfiguration=""
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_CalculationServiceInterface"
contract="ICalculationService" />
</service>
</services>
Error:: No protocol binding matches the given address 'http://10.10.179.180/C:/Documents and Settings/U16990/My Documents/Visual Studio 2010/Projects/CalculationService/CalculationService/CalculationService.svc/CalculationService'. Protocol bindings are configured at the Site level in IIS or WAS configuration.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
What can we do to correct it?
Note: I am testing the service with Visual Studio 2010.
Reference:
Hosting a Simple Wcf Service in Console
error "No protocol binding matches the given address ..."
How to derive a website absolute file path from a WCF service hosted in IIS?
An endpoint address is not a location of a file, but the URI at which the client can/will find the service. You should probably use something like this:
<service name="CalculationService.CalculationService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint
address="http://10.10.179.180/CalculationService/CalculationService.svc"
behaviorConfiguration="" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_CalculationServiceInterface"
contract="ICalculationService" />
</service>
In this case you're using a full URI instead of a relative one. In your client you must make sure that the endpoint refers to the same address, and you're good to go.

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

Infopath 2007 and WCF Data Connection

I am having trouble trying to connect an Infopath 2007 form to an WCF web service. I appears that the Infopath only wants to communicate via a SOAP 1.0 message. To get around the issue for the moment I have created an .asmx web service. Should I consider continuing down this workaround or figure out a way to get WCF to dish out SOAP 1.0 1.1 messages?
You get WCF to work with InfoPath by using basicHttpBinding instead of wsHttpBinding in webconfig.
Just to help with the answer by xanax this is what I ended up doing in the web.config file. this is a part of the default config that gets generated when you create a new WCF service. I commented out the one endpoint and added a new one with the only change being the binding from wsHttpBinding to basicHttpBinding and it worked.
<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!-- Service Endpoints -->
<!--<endpoint address="" binding="wsHttpBinding" contract="IService">-->
<endpoint address="" binding="basicHttpBinding" contract="IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
...Other Config Here....
<system.serviceModel>
InfoPath by default works only with basicHttpBinding. When using webservice with InfoPath, typically the webservice URL is put in a UDX file. In that file, there is no way to specify a binding for the target service. You do not typically create a proxy for your service yourself, InfoPath does it for you behind the scene and that proxy only uses basicHttpBinding.
If you want your InfoPath forms to work with a WCF service which uses a non basicHttpBinding, you can do so by creating a proxy yourself programmatically in your InfoPath form code. When you are creating the proxy programmatically you can specify your target WCF service's binding in proxy's constructor. No limitation exists when you use the programatically created proxy. Of course, .NET 3.5 should already have been installed so that WCF libraries are available to your code to create those proxies with right bindings. When you install InfoPath, only .NET 2 is available.
I have tried this with wsHttpBinding and it worked without a problem. From reading many articles and posts, it appears many people believe InfoPath can only work with basicHttpBinding. That is only partially true, because it applies only when you do not create your proxies yourself.

WCF address does not match what I specify in my web.config

In my web.config, I have specified
<services>
<service name="Querier.WCF.Querier"
behaviorConfiguration="QuerierServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://myserver:8000/SearcherService"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://myserver:9000/SearcherService"
binding="netTcpBinding"
bindingConfiguration="Binding1"
contract="Querier.WCF.IQuerier" />
</service>
</services>
However, the site is not available at http://myserver:8000/SearcherService,
I for some reason have to go to:
http://myserver/SearcherService/SearcherService.svc
(notice the port is missing)
When I go there, it tells me to run
svcutil.exe http://myserver.mycompanyname.com/SearcherService/SearcherService.svc?wsdl
It added a domain name for some reason and when I try to access the service with WCF storm,
I put in http://mymachine/SearcherService/SearcherService.svc, it discovers all the function names fine, but when I try to run one, I get:
There was no endpoint listening at
net.tcp://myserver:9000/SearcherService
that could accept the message. This is
often caused by an incorrect address
or SOAP action. See InnerException, if
present, for more details.
Any ideas as to why my service URL doesn;t match what I specified in the web.config?
NOTE:
I have set nettcp on the app in IIS and enabled the binding on 9000:*
When you host a WCF service in IIS it is IIS and its configuration who decides the base address for your service and you can only specify relative addresses. The baseaddress only applies to self hosted services.