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
Related
I am making WFC service. When I debug it from Visual Studio all is ok, but I've faced with problem when I deploy it on real IIS.
After deploying I still can get WSDL but when I request WebGet method (which returns a simple XML document) method I got the following error:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
What can be cause of problem?
My Web.Config:
<system.serviceModel>
<services>
<service name="XXXX.TSDX.UI.TsdxService">
<endpoint
address="Tsdx"
binding="webHttpBinding"
bindingConfiguration="TestBinding"
behaviorConfiguration="RESTFriendly"
contract="XXXX.TSDX.UI.ITsdxService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="TestBinding" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RESTFriendly">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Verify that the correct version of the .NET framework selected in the ASP.NET tab (in IIS) for your application
If you are hosting this service in MVC app please make sure to add below line to ignore controller routing conflict, I had this issue after struggling for sometime I found this answer which has resolved the issue.
routes.IgnoreRoute("{allsvc}", new { allsvc = #"..svc(/.*)?" });
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'm creating a WCF4 service with REST and SOAP endpoints to be hosted in IIS 7.5.
I have used the WCF4 REST template as an example.
However I have a few questions regarding my setup so far.
Here's my webconfig
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MEXGET">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MEXGET" name="Project.WebService.VehicleService">
<endpoint
address=""
behaviorConfiguration="REST"
binding="webHttpBinding"
contract="Project.WebService.IVehicleService" />
<endpoint
address="soap"
binding="basicHttpBinding"
contract="Project.WebService.IVehicleService" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
I have removed the standardEndpoints section and added endpoints of my own.
There are no .svc files as I've set the routes in the global.asax as shown below
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("VehicleService", new WebServiceHostFactory(), typeof(VehicleService)));
}
The help pages can be accessed via http://localhost:1313/ServiceTest/VehicleService/help
I've also used the WCF Test Client to access http://localhost:1313/ServiceTest/VehicleService/mex
which shows the metadata for the SOAP endpoint
But how do I retrieve the WSDL of the service?
With an svc file I can find the wsdl at http://localhost:1313/ServiceTest/VehicleService.svc?wsdl However I do not have a .svc file.
And neither can I find the WSDL at http://localhost:1313/ServiceTest/VehicleService?wsdl or http://localhost:1313/ServiceTest/VehicleService/soap?wsdl
Do I need to add a .svc file if I want to publish WSDL for the SOAP endpoint?
I have managed to get the WSDL working at http://localhost:1313/ServiceTest/VehicleService?wsdl.
The solution was using new ServiceHostFactory instead of new WebServiceHostFactory in the global.asax.
With WebServiceHostFactory you lose the WSDL functionality.
A similar question can be found here:
ServiceRoute + WebServiceHostFactory kills WSDL generation? How to create extensionless WCF service with ?wsdl
You should be able to get the WSDL by using the mex URL directly from the browser:
http://localhost:1313/ServiceTest/VehicleService/mex
The WcfTestClient is almost certainly doing that to retrieve the WSDL so it can generate the proxy to the service.
Im new in WCF.
I have WCF service with method
public string DoSomething(int i);
I call this method from one client and next client can`t get results from this method until the first client finishes method.
How to make this calls asynchronous?
My WCF Service:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService
My config:
<system.serviceModel>
<services>
<service name="MyService" behaviorConfiguration="ServiceBehavior">
<endpoint contract="IMyService" binding="basicHttpBinding"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<!--true-->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
If you want to make asynchronous calls to your service:
In Visual Studio Solution Explorer navigate to your Service Reference in the the project that contains your client application. Right click your Service reference and choose "Configure Service Reference", then check the box "Generate Asynchronous Operations", then click OK.
It shouldn't be necessary though because you can configure your service to handle multiple requests. You may want to look at how you have configured InstanceContextMode and ConcurrencyMode. The basicHttpBinding doesn't support sessions so your service is probably defaulting to InstanceContextMode.PerCall. For more details see Sessions, Instancing, and Concurrency
Maybe you have something limiting the number of calls. For more details see ServiceThrottlingBehavior
Once again, as a beginner with WCF, MVC and Sharp Architecture, i might asking a stupid question, so bear with me.
I'm finally able to make the Northwind example of Sharp Architecture work.
I can browse the service using internet browser
localhost/NorthwindWcfServices/TerritoriesService.svc
localhost/NorthwindWcfServices/TerritoriesService.svc?wsdl
I can invoke the service GetTerritories using WcfTestClient.exe
And then i use Fiddler to test it :
Fiddler is ok when i Request a GET :
localhost/NorthwindWcfServices/TerritoriesService.svc?wsdl
when i start requesting
localhost/NorthwindWcfServices/TerritoriesService.svc/GetTerritories
They keep giving me a 400 Bad Request error.
Is there something i should do to make it work ?
Should i add a content-type in fiddler header request ? or should i add any attribute in the service class ?
Any help will be much appreciated.
Thanks
You have to configure the Service using the Web config file for example if u configure the WCF for accessing ... your service config should look something like this
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndPBehavior">
<webHttp/>
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="CastleTest.WCF.WCFService">
<endpoint address="" binding="webHttpBinding"
contract="CastleTest.WCF.IWCFService"
behaviorConfiguration="EndPBehavior"/>
</service>
</services>
try it and see if the error 400 goes or not