WCF service endpoints give a 404 error - c#

I have a WCF service setup in a project that is used for ajax calls. I am able to access the service's main page (~/AjaxService.svc) without problems but when I try to access the endpoints it will give a 404 error, NOT an "Endpoint not found." message.
Other developers on my team use the exact same code branch without any trouble. This has worked in the past and has only recently started to show this error. In iis the application(s) the code runs through is using asp.net 4.0, but I do have older revisions that use asp.net 2.0 and these endpoints work.
AjaxService.svc
< ServiceHost Language="C#" Debug="true" Service="MyCompanyService.AjaxService" >
web.config
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="MyCompanyService.AjaxServiceAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyCompanyService.AjaxService">
<host>
<baseAddresses>
<add baseAddress="/ajax/AjaxService.svc"/>
</baseAddresses>
</host>
<endpoint address="/service1" behaviorConfiguration="MyCompanyService.AjaxServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyCompanyService.IService1"/>
<endpoint address="/service2" behaviorConfiguration="MyCompanyService.AjaxServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyCompanyService.IService2"/>
<endpoint address="/service3" behaviorConfiguration="MyCompanyService.AjaxServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyCompanyService.IService3"/>
<endpoint address="/service4" behaviorConfiguration="MyCompanyService.AjaxServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyCompanyService.IService4"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

Related

Custom Binding WCF with tcpTransport

I have a WCF Service hosted on a Windows Service that runs on the same network using its own credentials. Security is not important. However, speed and reliability are important.
So, I tried with a netTcpBinding binding. However, I noticed that when I reference the Service into the client. It adds to the configuration file the identity tag with the information of the account that the service is running on:
<identity>
<userPrincipalName value="account#domain" />
</identity>
I really don't want to have this in the client's configuration file, nor I want to pass it programmatically.
When I use instead a basicHttpBinding, I noticed that it does not add this tag. However, I still want to stick with net.tcp. So, my next try was to use a customBinding
So, here is where my problem is. I am not able to reference the custom binding to the client. Can someone verify my configuration? Also. Will this be enough to ignore completely the identity tag? If this is not the proper way, what would be the proper way? Thanks
<system.serviceModel>
<services>
<service name="LicenseServiceLogic.LicenseService">
<endpoint address="net.tcp://localhost:8000/LicenseService"
binding="myCustomBinding"
contract="LicenseServiceLogic.ILicenseService">
</endpoint>
</service>
</services>
<bindings>
<customBinding>
<binding name="myCustomBinding">
<compactMessageEncoding>
<binaryMessageEncoding/>
</compactMessageEncoding>
<tcpTransport listenBacklog ="100"
maxBufferPoolSize ="524288"
maxBufferSize ="2147483647"
maxReceivedMessageSize ="2147483647"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint binding="customBinding"
bindingConfiguration="myCustomBinding"
contract="IMetadataExchange"
name="http" />
</client>
</system.serviceModel>
First, the reason that we could not reference the custom binding to the client is we should add MEX service endpoint and enable the service metadata behavior. Like below,
<system.serviceModel>
<services>
<service name="VM1.MyService" behaviorConfiguration="mybehavior">
<endpoint address="" binding="netTcpBinding" contract="VM1.IService" bindingConfiguration="mybinding">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5566"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="mybinding">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Besides, if we don’t want to add the identity tag to the client configuration, just we need to do is to set the Security Mode to NONE. As shown above.
For Mex endpoint details.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/metadata
Feel free to let me know if there is anything I can help with.

Hosting WCF SOAP, and WCF REST service as Azure App Services

I am trying to host existing WCF service and a WCF REST service as a Azure App Services. I have used the Publish option from Visual studio like in the post Here
I am able to browse to the hosted URL for the WCF SOAP site and the WCF REST site, but when i add a service reference for the WCF SOAP site and call a method on it i get below error
Same with the WCF rest service when i call a REST method, i get 404 now found error.
There was no endpoint listening at https://wcfservice.azurewebsites.net/WebService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
From the failed request log i.e w3svcxxxx log, it says the request https://WcfService:80/Webservice.svc 404 not found status.
For the WCF Rest Service
https://WcfService:80/RESTservice.svc/GetData 404 not found status.
Why is the service internally calling a https://WcfService:80, would this require an configuration to setup. Tried to search around to see if i could find any help around this but could not find much.
Also, i have another WCF site that i had deployed to the App Services, which is setup with a basicHttpBinding and this site worked fine and i was able to get data using it.
Below is the web.config setting on the web site, i am using wsHttpBinging for the WCF SOAP service
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WebServiceOnline">
<!-- 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>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="WcfService.WebServiceOnline" behaviorConfiguration="WebServiceOnline">
<endpoint binding="wsHttpBinding" bindingName="wsSecurityByTransport" contract="WcfService.IWebServiceForOnline" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="WcfService.RESTService" behaviorConfiguration="WebServiceOnline">
<endpoint address="" binding="webHttpBinding" contract="WcfService.IRESTService" name="RunningBarbus.Services.RunningBarbusService" behaviorConfiguration="AjaxBehavior">
<identity>
<dns value="locahost" />
</identity>
</endpoint>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsSecurityByTransport">
<security mode="Transport">
<transport clientCredentialType="None" />
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services> <service name="WcfService.WebServiceOnline" behaviorConfiguration="WebServiceOnline">
<endpoint binding="wsHttpBinding" bindingName="wsSecurityByTransport" contract="WcfService.IWebServiceForOnline" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> <service name="WcfService.RESTService" behaviorConfiguration="WebServiceOnline">
<endpoint address="" binding="webHttpBinding" contract="WcfService.IRESTService" name="RunningBarbus.Services.RunningBarbusService" behaviorConfiguration="AjaxBehavior">
<identity>
<dns value="locahost" />
</identity>
</endpoint>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> </service> </services>
There may be an issue in the configuration file. We could expose the additional service endpoint for wshttpbinding.
Here is my configuration, and it works properly over Azure.
<system.serviceModel>
<services>
<service behaviorConfiguration="mybehavior" name="WcfService1.Service1">
<!--http, https are all configurated-->
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev" bindingConfiguration="mybinding"></endpoint>
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev" bindingConfiguration="com"></endpoint>
<endpoint address="myservice" binding="wsHttpBinding" contract="WcfService1.IService1"></endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="mybinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:10:00" receiveTimeout="00:10:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
<binding name="com">
<security mode="None"></security>
</binding>
</webHttpBinding>
</bindings>
Result
Feel free to let me know if there is anything I can help with.

Windows Service hosting WCF service can only be accessed by my domain user

I had developed a windows service that hosts a WCF service. The service is installed on a server and the idea is to process some files on the local network (domain). Also, the service is executing as my domain user.
the configuration of the service is this:
<system.serviceModel>
<services>
<service name="Zeus.My.Upload.Service.MyHostedService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:1089/Domain/Service"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:1089/Domain/Service/Uploader" binding="basicHttpBinding" contract="Zeus.My.Upload.Contract.IHostedService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="4294967296" transferMode="Streamed" sendTimeout="01:00:00" messageEncoding="Mtom">
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The issue with this configuration is that only my user is able to access and use this service. Other users of domain cannot even access to the URL.
How can I solve this issue?

Can I use netTcpBinding for WCF services hosted outside of IIS?

My WCF service is being hosted as a Windows managed service, so I'm unsure of whether or not I can still use the netTcpBinding. I've tried following a couple of guides at MSDN, but for some reason my service always fails to start whenever I do the switch from basicHttpBinding. Perhaps there are additional steps that services outside of the IIS are required to undergo?
Yes you can host WCF service with netTcpBinding outside of IIS, in Windows service or even Console Application if you want to.
Here is config file sample:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior"
name="XX.XX.Service">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="BindingConfiguration"
contract="XX.XX..IService" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/XXService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding
name="BindingConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
[Edit]
Problems with your config file:
base address is http instead of net.tcp
metadata endpoint is mexHttpBinding instead of metTcpBinding
security - by default windows authorization will be used, if test communication between to boxes, you might have permission problem. I suggest to start with security mode None and then adjust security when everything else works.
you don't need to specify httpGetEnabled for service behavior
if the port that you are going to use is already in use, you will not be able to start service
You absolutely can, and I'd go so far as to say you should.
Here's your problem:
<services>
<service name="Server.FileService" ...
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Test/file"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="Server.IFile" />
<endpoint address="mex" binding="mexHttpBinding" ...
The net.tcp address must have a net.tcp:// prefix, not a http:// prefix.
I don't normally use baseAddress so can't give advice on that. I'd remove baseAddress and instead use
<endpoint address="net.tcp://localhost:8001/Test/file" ..
(note that I would also choose another port over 8000)

Discover WCF hosted by Windows Service

In the solution, 4 projects : Business, the WCFService and the WCFServiceHost (a windows service) and a client
When I work in the solution, no problem, I can discover and create the proxy in the client.
When I install the host service, I start it but impossible to discover and create the proxy from visual studio with this : net.tcp://localhost:9100/MyApplicationWcf
Any idea ?
Thanks,
update #1
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyApplicationWcf.MyClassWcf">
<endpoint address="net.tcp://localhost:9100/MyClassWcf"
binding="netTcpBinding"
bindingConfiguration=""
name="MyClassWcf_Tcp"
contract="MyApplicationWcf.MyClassWcf" />
<endpoint name="mexHttpBinding"
contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
</system.serviceModel>
</configuration>
If you want to discover the service over net.tcp, you will need to define a MEX endpoint (metadata exchange) that uses the mexTcpBinding.
<behaviors>
<serviceBehaviors>
<behavior name="MexBehavior" >
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="mexBinding" portSharingEnabled="true">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="YourServiceImpl"
behaviorConfiguration="MexBehavior">
<host>
<baseAddresses>
<add baseAddress ="net.tcp://localhost:9100/MyApplicationWcf/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding"
contract="IYourServiceContract" />
<endpoint address="mex"
binding="mexTcpBinding" bindingConfiguration="mexBinding"
contract="IMetadataExchange" />
</service>
</services>
Do you have that??
Check out: How to: Publish Metadata for a Service Using a Configuration File for more information.

Categories

Resources