I've coded a WCF service that is external to the solution I wish to use it in. I'm doing this so that I can have one service that's reusable across many solutions. We've already duplicated this service many times as an asmx integral to the solution and it's not a good maintenance scenario. I'm finally able to have time to tackle gettign this working the right way. Any help will be greatly appreciated! All the posts I've seen about this take me in circles. My solution (and the service) is in VS2010, Framework 4.0, vb.net.
When using the webHttpBinding binding in the endpoint, when I add the service to my solution the reference is getting added, but web.config does not get added with the system.serviceModel configuration group that is needed. All the articles I can find talk about making the service part of the solution but that is what I'm trying to avoid.
Any ideas? Here is the system.serviceModel section of my service's web.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="Com.mydomain.Services.WCF_ACE.ACE">
<endpoint address=""
behaviorConfiguration="AspNetAjaxBehavior"
binding="webHttpBinding"
contract="Com.mydomain.Services.WCF_ACE.I_ACE" />
</service>
</services>
So you are trying to use a wcf service you built. It looks like clients section is missing in the attached config file.
And client configuration is always going to be different from service config. And you can add that manually to the client solution.
Related
I'm developing a REST service using WebHttpBinding.
Everything is perfect in my service, but while running it gives Error Endpoint not Found.
The web.config File is like this:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<services>
<service name="Service">
<endpoint address="http://localhost:10492/Service.svc" binding="webHttpBinding" contract="IService" behaviorConfiguration="webby"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webby">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
In address I tried like this also:
<endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="webby"/>
But it's still not working.
Here is a good link to get you started: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx
On what address are you attempting to connect to your web service? (Have you tried navigating to the address in your web browser, and what URL did you type in?)
[EDIT]
Being that you are hosting in a web application, IIS (or whatever web server you are using) will expect that a service descriptor file exists for your service. You cannot just create a URI in the web.config, and host it in IIS without an associated 'service' file on the file-system (this is your Service1.svc file).
This is a nuance specific to hosting WCF services within Internet Information Services - it is easy to forget about this step, if you are reading tutorials designed for self-hosted scenarios.
Make sure that you have a file in your website called "Service1.svc" and it should contain something like this:
<%#ServiceHost Language="C#" Service="MyNamespace.Service1" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Here is a tutorial on hosting REST services within IIS: http://saravananarumugam.wordpress.com/2011/03/04/simple-rest-implementation-with-webhttpbinding/
Another concern that jumps out at me, is that your endpoint address you have defined ("http://localhost:10492/Service.svc") does not conform to REST conventions. I wouldnt expect this would be your problem, but it is A problem.
I have around 15-20 services - each service has its own contract and implementation file. I want to host all these service in a console app so that it will be easier to debug during development.
Project structure
Services - Solution
ServiceContracts - Project
Implementation - Project
ServiceHost - Windows Service project -- Already inplace and working fine..
ServiceConsoleHost - Project - Currently working on it.
I have an app.config file in the ServiceConsoleHost project here the sample text from config file...
<service name="TestpricingService" behaviorConfiguration="HostBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/testService/pricingService"/>
</baseAddresses>
</host>
<!-- use base address provided by host -->
<endpoint address="net.tcp://localhost:820/testService/pricingService"
binding="netTcpBinding"
bindingConfiguration="HostBinding"
contract="Test.Services.Contracts.IpricingService" />
<!-- the mex endpoint is exposed at http://localhost:8000/testService/purchasing/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<behaviors>
<serviceBehaviors>
<behavior name="HostBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
<behavior name="PooledHostBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<ObjectPoolingServiceBehavior minPoolSize="0" maxPoolSize="5" idleTimeOut="30000"/>
</behavior>
</serviceBehaviors>
</behaviors>
Thanks in advance...
You are probably looking for self-hosted services. See MSDN Reference on self-hosting using ServiceHost.
Also take a look at enumerating WCF configuration bindings. Here is an SO post which describes enumerating WCF service and endpoint bindings.
as everyone mentioned you need 15 ServiceHosts to host 15 services. However they are not blocking. If you notice the MSDN code just sits waiting for a keypress whilst the service is running. This means all the service code is running on separate threads. So creating and hosting 15 services is not an issue. You dont need a "loop" as that is already handled once you do ServiceHost.Open().
I am consuming a third party WCF service and its config is below (a portion of it). I wanted to assign serviceBehaviors to endpoint, but there is no <service> tag here. In this case, how do you assign 'serviceBehaviors'?
<client>
<endpoint address="https://something/someservice.asmx" binding="customBinding" bindingConfiguration="ABCBinding" contract="Democlient.Soap" name="Soap" behaviorConfiguration="SoapEndpointB" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="SoapEndpointB">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="SoapServiceB">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
You assign serviceBehaviors to WCF server endpoints, not to client endpoints. You would have to request the 3rd party WCF service host add the service behaviors you seek if you need them changed.
It looks like the configuration you're showing is your client side configuration. That just indicates how you're going to be communicating with the service. It doesn't tell the service anything about your client.
Remember that the service has no knowledge of the client, and the only knowledge that the client has of the service is via metadata exchange.
Unless the service offers some method for doing so (not via any .Net or WCF mechanism), your client can not specify how the service should behave, nor should it. A given service may be handling requests from many different clients, each with their own desires. There's just no good way to handle that kind of situation.
I created a web service for which I am trying to provide 3 endpoints with different bindings.
1. basicHttpBinding,
2. wsHttpBinding,
3. webHttpBinding
When I make the service reference, I get only the endpoints with the basicHttpBinding and wsHttpBinding bindings created. I don't get webHttpBinding. What could possibly wrong.
Here's the structure of the serviceModel node in web.config.
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
</diagnostics>
<services>
<service behaviorConfiguration="VersionTolerance.Service1Behavior" name="BookShop.BookShopService">
<endpoint address="sadha" binding="basicHttpBinding" contract="BookShop.IBookShopService" />
<endpoint address="ws" binding="wsHttpBinding" contract="BookShop.IBookShopService" >
</endpoint>
<endpoint address="web" binding="webHttpBinding" behaviorConfiguration="webHttpBehavior"
contract="BookShop.IBookShopService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:49654/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VersionTolerance.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
There's nothing wrong - that's just the way it works!
basicHttpBinding and wsHttpBinding are SOAP bindings that expose metadata about their service - your Visual Studio Add Service Reference can interrogate their endpoints, find out what they're called, what methods they offer, what data types they expect as parameters and what they return.
webHttpBinding is REST - and REST by default doesn't have a concept of metadata - you won't get a service description, list of methods etc. - REST is all about resources - not methods.
So therefore, when you do a Add Service Reference, you get proxy clients for the SOAP endpoints - but not for the REST / webHttpBinding endpoint. Works as designed.
The WCF Data Services - built on top of REST - offer a similar experience to the SOAP bindings, in that you can do an Add Service Reference and get a nice client side proxy and all - and this is done since the OData protocol defines a metadata exchange on top of REST. So if you can turn your REST service into a WCF Data Service, you'd be fine again.
Otherwise, with REST, you just have to "know" (from a documentation page or something) what the resource URI's for your REST service are, and what the HTTP verbs do in your REST context.
I have a simple WCF 4.0 service with some simple methods and a property with a getter that returns List. The service works fine when connected to programatically. The getter is decorated as are the other methods on the Interface that define the service contract.
My next move is to make the service accessible via the IE web browser so server/deployment admins can do a "smoketest" after service installation.
This works currently:
http://localhost/myservice.svc?wsdl
But I need to take things further and get this to work:
http://localhost/myservice.svc/SmokeTest
and have results show in the browser, SmokeTest is the property with a getter that does stuff and returns the List I want to show in the browser.
So far I can't figure out what my config should look like. All help appreciated.
This is all I have in the web.config for the service. The endpoint is myservice.svc:
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="myservice.worker" >
<endpoint address="" binding="basicHttpBinding" contract="myservice.IServicio" />
</service>
</services>
related question, an explanation of what can and can't be done:
Invoking WCF services through a browser