Endpoint not found When Hosting in ASP.NET - asp.net

I get "Endpoint not found" when attempting to access my service via the browser at
http://localhost:10093/Services/Service1.svc
I get "Error: Cannot obtain Metadata from http://localhost:10093/Services/Service1.svc" when attempting to access the same address from the wcftestclient.
If I place a breakpoint in the service implementation it is hit, so I assume the svc file is setup correctly:
<%# ServiceHost Language="C#" Debug="true"
Service="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service"
Factory="CommonServiceFactory.WebServiceHostFactory,CommonServiceFactory" %>
Here is my config:
<system.serviceModel>
<services>
<service name="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service"
behaviorConfiguration="MainServiceBehavior">
<endpoint name="newEndpoing"
binding="basicHttpBinding" bindingConfiguration=""
contract="MyApp.Core.Service.IMyAppService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MainServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

So you have a *.svc file to host your service. Can you right-click in Visual Studio on that file and say "Show in Browser" ? Do you get anything there, or does it throw an error right away??
Next: your service endpoint has no address="" attribute, which I believe is mandatory - try adding that (even if you don't specify an address in it).
If you're hosting in IIS, your service address is defined by the virtual directory where your SVC file is present, and the SVC file itself - you might not be able to define a specific port or anything (IIS will handle that).
So try to connect to
http://localhost/Services/Service1.svc
Does that work by any chance??
Update: reading your post again more closely, you're specifying a special factory for the service - WebServiceHostFactory. Is this the default WebServiceHostFactory provided by .NET, or is that something you built yourself??
The point is: the .NET WebServiceHostFactory will use the webHttpBinding for RESTful WCF services - that won't work with an endpoint specifying basicHttpBinding, nor will the REST service have any metadata....
Update #2: try to use just the service's fully qualified class name, but without the assembly specification, in both your SVC file, and the config file.
So change this:
Service="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service"
to this:
Service="MyApp.Core.Service.Service.MyAppService"
SVC file:
<%# ServiceHost Language="C#" Debug="true"
Service="MyApp.Core.Service.Service.MyAppService" %>
Config file:
<services>
<service name="MyApp.Core.Service.Service.MyAppService"
behaviorConfiguration="MainServiceBehavior">
<endpoint name="newEndpoing"
binding="basicHttpBinding" bindingConfiguration=""
contract="MyApp.Core.Service.IMyAppService" />
</service>
</services>

On your Solution Explorer, open your .svc by using "view markup", make sure you have something like:
... ServiceHost Language="C#" Debug="true"
Service="Yourservice.yourservice" CodeBehind="yourservice.svc.cs" %>
Where Yourservice is your namespace and yourservice is name of your .svc created.

I had the same results (Endpoint not found) when I put this in the browser window
http://c143253-w7a:2221/ws/myService.svc
Then when I put the whole url to the method, it ran fine. Like this
http://c143253-w7a:2221/ws/myService.svc/HelloWorld?theInput=pds
In my .svc file I am using this
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
I think that the Factory doesn't spin up the endpoint until it is needed. That is why we get Endpoint not found in the browser(?).
Here is what the method signature looks like in the interface code.
using System.ServiceModel.Web;
[WebGet(UriTemplate = "HelloWorld?theInput={theInput}")]
[OperationContract]
string HelloWorld(string theInput);
I put nothing in the webconfig. There is some stuff in there, but I think that came in w the VS, Add WCF Service template. It looks like this:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

my web.config for my WCF service is very similar to yours. You definitely have to add the MEX endpoint like Shiraz said. I've added a behavior configuration that lets any message size go through the WCF. Try to use these settings if it can help you (don't forget to change the contract settings):
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="524288000" maxBufferPoolSize="524288000" maxReceivedMessageSize="524288000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="500000000" maxStringContentLength="500000000" maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="">
<extendedProtectionPolicy policyEnforcement="Never"/>
</transport>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="serviceBehavior" name="RC.Svc.Web.TPF.Service">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService"
contract="RC.Svc.Web.TPF.IService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<client />

Your error message is "Cannot obtain Metadata" and you do not have a MetadataExchange endpoint defined. You do have httpGetEnabled="True", which is also required.
Try defining a MEX endpoint, for details how to see: http://bloggingabout.net/blogs/dennis/archive/2006/11/09/WCF-Part-4-3A00-Make-your-service-visible-through-metadata.aspx

Related

WCF service call returns empty file / page

The problem:
When I'm calling my deployed WCF service, the browser downloads an empty svc file and does not show me the page with the service xml file.
The context:
I have to move the webapp hosting the WCF service to a new server. This service was working fine on the old server, that was running IIS.
The new server has 2 webservers running. IIS 8.5 and WAMP 2.5, because the server hosts an Php app and Jira.
The setup:
The WAMP server listens to the 80 port and then redirects to IIS, to a specific port, if needed. This is an example for the setup.
Wamp config (https-vhosts.confg):
<VirtualHost *:80>
ServerName site.de
ServerAlias www.site.de
<Proxy *>
Require all granted
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:9050/
ProxyPassReverse / http://localhost:9050/
The service URL:
https://www.site.de/folder/service.svc
Service config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="someBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="52428899">
<readerQuotas maxDepth="64" maxStringContentLength="81920" maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="LargeServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<useRequestHeadersForMetadataAddress />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
<endpoint address="http://www.site.de/folder/service.svc"
binding="basicHttpBinding"
bindingConfiguration="someBinding"
contract="ExampleServiceModels.IExampleService" />
</service>
</services>
I have never worked with wamp before. And I don't have much experience with WCF settings also. Any ideas or tips would be highly appreciated.
EDIT
Using the wcf test client i get this:
Error: Cannot obtain Metadata from http://www.site.de/folder/ExampleService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://www.site.de/folder/ExampleService.svc Metadata contains a reference that cannot be resolved: 'http://www.site.de/folder/ExampleService.svc'. The requested service, 'http://www.site.de/folder/ExampleService.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://www.site.de/folder/ExampleService.svc The document at the url http://www.site.de/folder/ExampleService.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:- Report from 'XML Schema' is 'Root element is missing.'.- Report from 'DISCO Document' is 'Root element is missing.'.- Report from 'WSDL Document' is 'There is an error in XML document (0, 0).'. - Root element is missing.
You need to specify a MEX (meta data exchange) binding to expose you WSDL. Example (look at the address "mex"):
<service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
<endpoint address="http://www.site.de/folder/service.svc" binding="basicHttpBinding"
bindingConfiguration="someBinding"
contract="ExampleServiceModels.IExampleService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
To get the wsdl type in the browser:
https://www.site.de/folder/service.svc?wsdl
Not sure this answer will help OP after almost 3 years. But it is more intended for #GothamLlianen. But if you want to access a WFC service on a HTTPS connection, you need to specify that binding explicitly.
Add this in the <system.serviceModel> node of the Web.Config
<bindings>
<webHttpBinding>
<binding name="HttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
Then add the name, in this case "HttpsBinding" to the endpoint
<endpoint bindingConfiguration="HttpsBinding"
The complete node below for reference
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="MyProject.Api">
<endpoint bindingConfiguration="HttpsBinding" address="" behaviorConfiguration="web" binding="webHttpBinding" contract="MyProject.IApi" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceAuthorization principalPermissionMode="UseAspNetRoles" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="HttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

WCF Services - Configuration web service binding exception

All,
Env:
Asp.net 4.0
IIS 7 (or greater)
WCF service consumed by SL component
Authentication:
Anonymous/Forms
When I attempt to browse to my WCF web service (using browser) I get the following exception on my web service, I need to get rid of this error:
The authentication schemes configured on the host ('IntegratedWindowsAuthentication') do not allow those configured on the binding 'BasicHttpBinding' ('Anonymous'). Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly. Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.
I looked at ALL related posts and none of them help me.
I am not using any authentication or user/pwd transmission for my service.
The service I need to get working is consumed by Silverlight component and has this name in web.config file:
Htmls.WebStore.Services.WebStoreServices (ignore the other service).
Here's my web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebStoreServices_InsecureTransport" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="4096" />
<security mode="None" />
</binding>
<binding name="basicHttpBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SitefinityWebApp.Sitefinity.Services.Content.EventsAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="EndpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="Telerik.Sitefinity.Web.Services.LocalizationBehavior" />
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Htmls.WebStore.Services.WebStoreServices">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="WebStoreServices_InsecureTransport" contract="Htmls.WebStore.Services.IWebStoreServices" />
</service>
<service name="SitefinityWebApp.Sitefinity.Services.Content.Events">
<endpoint address="" behaviorConfiguration="SitefinityWebApp.Sitefinity.Services.Content.EventsAspNetAjaxBehavior" binding="webHttpBinding" contract="SitefinityWebApp.Sitefinity.Services.Content.Events" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
The exception was caused by having incorrect permission on the folder where the xxxxx.svc file was. The folder was locked down using security permissions.

WCF Endpoint Configuration Issue

I'm getting the following error when my ASP.NET 4.0 site loads, and it's because of my WCF service settings in the web.config file (I'm just not enough of a WCF expert and Google isn't helping :)):
The endpoint at '[Path to my Service.svc]' does not have a Binding
with the None MessageVersion.
'System.ServiceModel.Description.WebScriptEnablingBehavior' is only
intended for use with WebHttpBinding or similar bindings.
I was using webHttpBinding but was getting the following error, so now I'm using basicHttpBinding after following the advice of this post:
Security settings for this service require 'Anonymous' Authentication
but it is not enabled for the IIS application that hosts this
service.
Anyways, here's the relevant info from my web.config. Please help!
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ABC.ProjectName.Web.ServiceBehavior">
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ABC.ProjectNameDell.Web.ServiceBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"
aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="webHttpBinding_AnonymousDisabled" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="ABC.ProjectName.Web.AjaxService" >
<endpoint address="/"
behaviorConfiguration="ABC.ProjectName.Web.ServiceBehavior"
binding="basicHttpBinding"
contract="ABC.ProjectName.Web.AjaxService" />
</service>
</services>
</system.serviceModel>
You can't use basicHttpBinding with enableWebScript. Set your binding to WebHttpBinding.
<service name="ABC.ProjectName.Web.AjaxService" >
<endpoint address="/" behaviorConfiguration="ABC.ProjectName.Web.ServiceBehavior"
binding="webHttpBinding"
contract="ABC.ProjectName.Web.AjaxService" />
</service>

Set up wcf service for http and https and also add username/password to its access

I am kinda new to WCF and the setting up of service and have 2 questions. My first question I have a service that will be accessed via https on a web server. However locally on my local IIS7, it will be accessed via http as https is not available. How can I set up a service to be accessed by both?
My second question is regarding how I can set up a service that requires a username and password to be accessed. The service that I have in place I dont want methods within it to be accessed unless the calling application has the rights to do so?
Here is an example of the relevant area of my web.config file.
<system.serviceModel>
<bindings>
<webHttpBinding>
<!-- standard AJAX binding that supports SSL -->
<binding name="TransportSecurity">
<security mode="Transport" />
</binding>
<!-- standard AJAX binding for HTTP only -->
<binding name="NoSecurity">
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="ServiceBehavior" name="ServiceName">
<endpoint address=""
behaviorConfiguration="EndPointBehavior"
binding="webHttpBinding"
bindingConfiguration="NoSecurity"
contract="App.Service.ServiceName" />
</service>
</services>
<diagnostics>
<messageLogging logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="false" logMalformedMessages="true" logEntireMessage="false" maxSizeOfMessageToLog="65535000" maxMessagesToLog="500" />
</diagnostics>
</system.serviceModel>
In this config, the service is set up for http only and not username/password applied to it.
You can add the username password configuration to your bindings:
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
and
<security mode="TransportCredentialOnly"> <!-- This means http + credential -->
<transport clientCredentialType="Basic" />
</security>
As for authorization, there are a bunch of options. The very simplest is to apply a custom username password validator (artibtrary example taken from Link):
<serviceBehaviors>
<behavior name="CustomValidator">
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType=
</behavior>
</serviceBehaviors>
At a more sophisticated level, read up on the ServiceAuthorizationManager:
http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceauthorizationmanager.aspx

Why does my WCF web service end the response when the output data is fairly large?

I've set up a WCF web service to be called from my web site. It's working great, but if I request a large amount of data (not sure on the size, but it's easily 3-4 times larger than the "standard" data I'm returning), Cassini (Visual Studio Web Server) just closes the response without sending anything-- no error or anything. Nothing in event log. Just nada.
I'm a newbie to WCF, but I know there must be some configuration option I'm missing here (like a message/response max size/limit) that solves my problem. Here's what my web.config section looks like:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<endpointBehaviors>
<behavior name="securetmhAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="tmhsecureBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="securetmh">
<endpoint address="" behaviorConfiguration="securetmhAspNetAjaxBehavior" binding="webHttpBinding" contract="securetmh" />
</service>
</services>
</system.serviceModel>
Any help would be appreciated.
For security reasons, WCF limits the data returned by a service call to 64 K by default.
You can obviously change that - there's a gazillion of entries to tweak. See this sample config here:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="customWebHttp"
maxBufferPoolSize="256000"
maxReceivedMessageSize="256000"
maxBufferSize="256000">
<readerQuotas
maxArrayLength="256000"
maxStringContentLength="256000"/>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="YourService">
<endpoint name="test"
address="....."
binding="webHttpBinding"
bindingConfiguration="customWebHttp"
contract="IYourService" />
</service>
</services>
</system.serviceModel>
You need to define a custom binding configuration based on the webHttpBinding, and you can tweak all those various settings - I set them all to 256K (instead of 64K).
Hope this helps!

Resources