Restful WCF can't reach operationcontract - asp.net

I created a RESFTful WCF web service and i installed it in IIS as a new web application. The WCF has some actions like: Login, getEmployees ...etc. and it works fine when i publish and run it from vs, so i can reach from browser links like:
http://myserver/service.svc
http://myserver/service.svc?wsdl
http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada
and with the action links i get the exact needed data as a response.
however it works only when i run the web service from vs, but when i try to reach the links from browser and the web service is NOT running in VS i can reach only links like:
http://myserver/service.svc
http://myserver/service.svc?wsdl
but not the operational links like:
http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada
Endpoints configurations:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings/>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="AXPAYROLL.PayrollActions" behaviorConfiguration="serviceBehavior">
<endpoint address="http://myserver/" behaviorConfiguration="RESTFriendly" binding="webHttpBinding" contract="AXPAYROLL.IPayrollActions">
<identity>
<dns value="myserver" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://myserver/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RESTFriendly">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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="True" />
<serviceAuthorization serviceAuthorizationManagerType="AXPAYROLL.DataContractLayer.DistributorValidator, AXPAYROLL" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I also created a console host application where everything worked just fine like from vs, so the problem in IIS for sure may be in permissions...
I am new in WCF but i believe that it can't be the right way to run vs always to get the wcf deployed!!! i also want to install the wcf on a productive server where no vs is installed, i know that the self hosting could be achieved with the console application but this is again not what i want, i want it torun over normal iis,any idea what is the problem? did i miss something?

When the WCF service on IIS, any base address specified in the <baseAddresses> will be ignored and the base address will be the URL to the .svc file.
The address attribute in the endpoint element is a relative address and could be like address="rest".
So in IIS, the url will be http://myserver/service.svc/rest/getEmployees?name=dada
Update:
To remove svc extension, have a look at this question

Related

ASP.NET WebServices web config file updated & HTTP 415 Error

I've developed a WCF webservice and deployed it to my web server. Testing my mobile application, the web service returns HTTP 415 Error. Wrong Media Type. So, I went into IIS Server Manager and added .svc mime type. My app worked once. I made some changes to the app and redeployed it, and the 415 error returned.
Please Remember This:
After you add mime type to your web service configuration, the Web.conf file is changed. IIS adds in the following:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
**<staticContent>
<mimeMap fileExtension=".svc" mimeType="application/octet-stream" />
</staticContent>**
Be sure to copy the StaticContent information back to your asp.net project web.config file. Otherwise, when you publish the app, it will overwrite the web.config file on IIS and your .json (and other site settings) will be gone. I finally remember this after 2 days of head-banging. Thanks, I hope this helps someone.
I erased my web service and re-wrote it. What I noticed is that Visual Studio does not put in the service endpoints to support JSON. Once I found that omission, I added:
<behaviors>
<endpointBehaviors>
<behavior name="jsonServiceBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
And don't forget to add in....
<staticContent>
<mimeMap fileExtension=".svc" mimeType="application/octet-stream" />
</staticContent>
I hope this helps someone.

Configuring and installing a WCF app on Windows Server 2012

I am working on a Web Service app. The tools in use for this project are a Windows Server 2012 Standard and Visual Studio Pro 2013. App is in C#, .NET 4.5
At this early point in the development of this app., it's in the proof of concept stage. No database, nothing fancy at all; trying to get the basic architecture to work. Running in the development environment, everything works fine. Publishing to the server does not work. I get 404 - File or directory not found when I try to open this page in a browser. On my development system/personal web server, I can see the results of the app running on the page displayed.
I have looked at a number of tutorials and step-by-step instructions on how to do this. This and this was very helpful.
After some work on the server side, I got the web deploy feature to work from my development system to the server. I have also tried other install techniques.
I have reached a wall in narrowing down the problem because I don't know IIS architecture all that well and that seems to be the problem, unless I have misunderstood some aspect of running my test/proof of concept. I have not gotten much help from my service provider running the server debugging this.
Any thoughts on how to narrow this problem; where to look, alternative tests to try, much appreciated.
web.config (this is the generic version generated by
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="Test.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8371/Design_Time_Addresses/Test/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="Test.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
</system.serviceModel>
</configuration>
adding this to the config solved the problem.
<system.webServer>
<handlers>
<add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" resourceType="File" requireAccess="Script" preCondition="integratedMode" />
</handlers>
</system.webServer>

WCF: How to combine several services into single WSDL

In my ASP.NET WebForms project I have a reference to the WCF services library project, which contains different WCF services for each business object. The services are hosted in IIS and it's possible to get WSDL via routes I defined in the Global.asax: one WSDL via one route for each service.
What I really need - some ability to choose services what I want to provide for different customers and generate a SINGLE WSDL for the chosen services set.
Yes its possible to configure WCF routing service and get WSDL files form individual service behind it.
Step 1 - Set HttpGetEnabled set to true and configure MEX Endpoint in all WCF Service those are behind your router service
<service behaviorConfiguration="routingBehv" name="System.ServiceModel.Routing.RoutingService">
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfRoutingService/RoutingService.svc"/>
</baseAddresses>
</host>
<endpoint address="http://localhost/WcfRoutingService/RoutingService.svc" binding="mexHttpBinding" name="mexEndpoint" contract="System.ServiceModel.Routing.IRequestReplyRouter"/>
</service>
Step 2- Configure Routing Service
Add Endpoint
<endpoint address="" binding="mexHttpBinding" name="mexEndpoint" contract="System.ServiceModel.Routing.IRequestReplyRouter"/>
Add service behaviour
<behaviors>
<serviceBehaviors>
<behavior>
<routing routeOnHeadersOnly="false" filterTableName="routingTable" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Client Endpoint address should specify the "MEX" endpoint address
<client>
<endpoint address="http://localhost/PremiumWcfService/PremiumWCFService.svc/mex" binding="mexHttpBinding" contract="*" name="PremiumServiceMex"/>
<endpoint address="http://localhost/StandardWCFService/StandardWCFService.svc/mex" binding="mexHttpBinding" contract="*" name="StandardServiceMex"/>
</client>
Specify the routing table
<routing>
<filters>
<filter name="StandardServiceMexFilter" filterType="EndpointAddress" filterData="http://tempuri.org/WcfRoutingService/RoutingService.svc/StandardService" />
<filter name="PremiumServiceMexFilter" filterType="EndpointAddress" filterData="http://tempuri.org/WcfRoutingService/RoutingService.svc/sPreminuService" />
</filters>
<filterTables>
<filterTable name="routingTable">
<add filterName="StandardServiceMexFilter" endpointName="StandardServiceMex"/>
<add filterName="PremiumServiceMexFilter" endpointName="PremiumServiceMex"/>
</filterTable>
</filterTables>
</routing>
You are all done.
You can directly access the WSDL file of your services by below URLS individually :
http://localhost/WcfRoutingService/RoutingService.svc/StandardService
http://localhost/WcfRoutingService/RoutingService.svc/PremiumService
the problem in your solution is : you give to your clients a WSDL with the address of your web service PremiumWCFService and StandardService , and the clients (WCF) can use that directly without check and can call your web sevices without call routing service.

Basic WIndows Workflows 4 Persistance in a webserver hosted .xamlx services not working

I'm trying to create a Windows Workflow 4 Service hosted in IIS. I've configured the service as below
<system.serviceModel>
<services>
<service name="ApprovalService" behaviorConfiguration="ApprovalServiceBehavior">
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ApprovalServiceBehavior">
<!-- 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" />
<sqlWorkflowInstanceStore connectionStringName="WorkflowPersistence" />
<workflowIdle timeToPersist="0" timeToUnload="0:05:0"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
The service does not persist! There's nothing magical in the service like custom persisting of values, etc. I've got it working in another service that does have a custom persistance method, but I can't figure out the difference.
Perhaps my service is erroring out, but I can not seem to figure out how to step into debugging either.
Any help would be greatly appreciated!
Assuming the name of your service element and the SQL connection string are correct you workflow should persist as soon as it goes idle. Did you try adding a Delay activity to ensure it goes idle or a Persist activity to force it to persist?
Try adding tracking or tracing to see what is going on. Something like
<system.diagnostics>
<sources>
<source name="System.Activities"
switchValue="Verbose">
<listeners>
<add name="textListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="MyTraceLog.txt"
traceOutputOptions="ProcessId, DateTime" />
</listeners>
</source>
</sources>
</system.diagnostics>

Webservices wcfstorm client

I am using WCFstrom lite to find the problem with the webservice connection. It comes up with the error
"
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.RSS Feed
"
But as it is lite version I cannot find any configuration on the wcfstrom.
My web config looks like.
<system.serviceModel>
<extensions>
<behaviorExtensions>
<!-- Declare that we have an extension called WSDL Extras-->
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<services>
<service name="xxxxxxxxxxxxxxxxxx" behaviourConfiguration="xxxxxxxxxxxxxx">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" behaviorConfiguration="WcfExtras.EndpointBehavior" contract="xxxxxxxxxxxx">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" behaviorConfiguration="WcfExtras.EndpointBehavior" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WcfExtras.EndpointBehavior">
<wsdlExtensions location="http://localhost:3893/xxxxxxxx.svc" singleFile="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="xxxxxxx.xxxxxxxx">
<!-- 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>
Where do I add the following code:
<bindings>
<basicHttpBinding>
<binding name="LoggedInUsersSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
I found the answer, just select the service in the wcf Client and edit on end points then you can edit the maxReceivedmessages property
In WCFStorm (at least in the current 1.3.0 version), you can also increase the MaxReceivedMessage by loading a client app.config file which has a the right (large) value.
http://www.wcfstorm.com/wcf/loading-client-appconfig-files.aspx

Resources