WCF Service error on IIS with metadata - wcf

I'm trying to publish a service to IIS, it builds and runs OK on the ASP.NET dev server. When running in IIS I can get to the metadata by navigating to the service or by adding service reference in Visual Studio. But when I call a method from my client app it crashes with a internal server error. So I went to the Event Log and found this:
WebHost failed to process a request.
Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/8810861
Exception: System.Web.HttpException (0x80004005): There was no channel actively listening at 'http://mysite.net/soundhubservice.svc/$metadata'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening. ---> System.ServiceModel.EndpointNotFoundException: There was no channel actively listening at 'http://mysite.net/soundhubservice.svc/$metadata'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
Process Name: w3wp
Process ID: 1080
My Web.Config looks something like this:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="SoundHub.Services.SoundHubService" behaviorConfiguration="StreamingServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost/SoundHubServive"/>
</baseAddresses>
</host>
<endpoint address="service" binding="basicHttpBinding" bindingConfiguration="httpBuffering" contract="SoundHub.Services.ISoundHubService"/>
<endpoint address="stream" binding="basicHttpBinding" bindingConfiguration="HttpStreaming" contract="SoundHub.Services.ISoundHubStreamService"/>
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="HttpStreaming" maxReceivedMessageSize="67108864" transferMode="Streamed"/>
<binding name="httpBuffering" transferMode="Buffered" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="StreamingServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Tried several combinations of settings I found while searching online but nothing helped, always the same error.
Thanks
Bruno

I had this problem when one of the objects I returned contained an enumeration; turns out it couldn't figure out how to serialize it.
If that's your problem, try returning the int value of the enum (or a string value) and cast it back to the enum on the client side.

Related

There was no end point listening at... error for wcf service

I know there are lot of posts for this issue and I tried solutions from most of them but nothing seems to work.
I have a WCF service which was working fine in the Dev box when hosted on IIS and I moved this to the UAT box app server and I am able to access it and test if from the test client. So I now hosted my MVC application on the web server and from the web server browser I am able to access the service but when I run my web application which consumes the service it throws the following error.
Error Detail:- There was no endpoint listening at http://servername/AC.IS.BLService/CustService
.svc that could accept the message. This is often caused by an incorrect
address or SOAP action. See InnerException, if present, for more details.
Error TargetSite:- ACL.IS.BLWebSite.ViewModels.HomeAccountStatusViewModel
ValidateLogin(ACL.IS.BLWebSite.ViewModels.HomeAccountStatusViewModel)
Inner Exception:- System.Net.WebException: The remote server returned an
error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at
System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannel
Request.WaitForReply(TimeSpan timeout)
So,I tried hosting the service and the web application together on the same server and I still have the same problem. The following are my config files for both the service and client
Client.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustomerService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://servername/ACL.IS.BLService/CustService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustService"
contract="BLService.ICustService" name="BasicHttpBinding_ICustService" />
</client>
</system.serviceModel>
Server Config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustService" />
</basicHttpBinding>
</bindings>
<services>
<service name="ACL.IS.BL_WebServices.CustService" behaviorConfiguration="mexBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/"/>
</baseAddresses>
</host>
<endpoint address="CustService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustService" contract="ACL.IS.BL_WebServices.ICustService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<!-- 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" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
its a windows 2012 server. IIS 8.5. Could somebody please help.
Just to mention..there is a firewall as well..does it have something to do with port numbers ?
Your server config says that it listens on port 8080:
baseAddress="http://localhost:8080/"
while client connects to port 80:
address="http://servername/ACL.IS.BLService/CustService.svc"
I think they should match.
You appear to have a contract mismatch.
Client;
contract="BLService.ICustService"
Server;
contract="ACL.IS.BL_WebServices.ICustService"
These need to match

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http]

I have been using http for all these and when i am working with net.tcp and when adding the reference i am getting an error like
Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
my web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="servicebehave" name="WcfServ.Service1">
<endpoint address="" binding="netTcpBinding"
bindingConfiguration="" name="nettcp" contract="WcfServ.IService1" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:51560/Service1.svc" />
<add baseAddress="http://localhost:8080/Service1.svc"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding">
<security mode="Transport" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="servicebehave">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false"/>
<!-- 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="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Can anybody tell me where i am doing wrong?
You can't host net.tcp under IIS 6, it supports only HTTP(s). So you are limited with HTTP bindings only (basic, ws or 2007). In order to provide net.tcp and other protocols, WAS is required. You can activate it standalone, but I advice you to install it both with IIS 7 (it is installed as a part of it), because IIS 7 gives a convinient service management platform in addition.
Another solution it so change the hosting environment to make it self-hosted or service-hosted, using ServiceHost class instance, which supports tcp protocol.
If you want to configure your wcf service for net.tcp in IIS 7 please refer to this answer:
WCF Service Base Address Http and netTcp
Regards

WCF REST communication with Windows Phone

I'm having some trouble regarding a rest request sent from my Windows Phone app via RestSharp to a self hosted WCF service I have made. The request works fine in the emulator and the request returns a result but when I try to perform the request on my app on an actual device it fails and the request does not return anything.
Having done a fair amount of research I have discovered that apparently webHttpBinding is not supported on Windows Phone and therefore I need to add a basicHttpBinding endpoint to my Web.config file. However, when I try to do this I get several errors associated with having more than one endpoint and I can't seem to get any solution to successfully work with both of these. Switching the endpoint to basicHttpBinding and commenting out webHttpBinding also causes an error when I navigate to localhost:81/mywebservice.svc
"System.InvalidOperationException: For request in operation analyseFace to be a stream the operation must have a single parameter whose type is Stream."
asking for the stream that should be attached with a request. It shows a normal help page using the original code and the same address.
My web.config file
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<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>
<behavior name="servicebehavior">
<!--<serviceMetadata httpGetEnabled="true"/>-->
<serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restbehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="servicebehavior" name="VizageAPIWebRole.vizage">
<endpoint address="" behaviorConfiguration="restbehavior" binding="webHttpBinding" name="RESTEndPoint" contract="VizageAPIWebRole.Ivizage" />
<!--<endpoint address="" binding="basicHttpBinding" contract="VizageAPIWebRole.Ivizage" />-->
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="RestBinding">
<readerQuotas maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" />
<security mode="None">
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
My WCF SERVICE
[ServiceContract]
public interface Ivizage
{
[WebInvoke(UriTemplate = "/agerecog/{auth}", Method = "POST")]
VizageResult analyseFace(string auth, Stream dataStream);
}
I'm wondering if someone can help me work out what code I have to edit in my web.config to make this work for both endpoints as I haven't had any luck so far with things I've tried
Your code seems to be a REST service, but basicHttpBinding supports SOAP. So please continue to use webHttpBinding. However, on the Windows Phone side, the WCF cannot be used, it is needed to use WebClient or HttpWebRequest to access a REST service. WCF can just help us to access a SOAP service.
In addition, you mentioned the application works fine in the emulator, so it is unlikely to be a coding issue. It would be better if you can check whether your real phone device is able to access internet. Please also make sure you're using the cloud service's address instead of 127.0.0.1. Local address will not work on a real device.
Best Regards,
Ming Xu.
From the exception and your config - you are using simplified configuration which by default uses basicHttpBinding. You have to explicity define service end point
<services>
<service name="WcfRest.Ivizage">
<endpoint behaviorConfiguration="restbehavior" binding="webHttpBinding"
contract="WcfRest.Ivizage" />
</service>
</services>
Edit: looks like webHttp is not supported

Building WCF Service library in MS Web Developer 2010 Express

I Created the WCF Service Library in MS Web Developer 2010 Express with ITestSerivce being the Service Contract and gaving following Web.config configuration. But im getting this error
:
Error: Cannot obtain Metadata from http://localhost:56016/TestService.svc
:
I dont understand why the url is http://localhost:56016 where in base address is http://localhost:8001
Can anybody help me with this issue.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="TestService">
<host>
<baseAddresses>
<add baseAddress ="http://localhost:8001/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ITestService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!--Setting httpGetEnabled you can publish the metadata -->
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="SampleServiceBinding">
<security/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
There are a few problems with the config above.
The service element has the name attibute which is not fully qualified name.
The endpoint element has the contract attribute value which is not fully qualified name.
A fully qualified name is as shown below:
MyWCFService.TestService (i.e. namespace.ServiceName)
If you are running the same on Cassini web server then right click on properties and under the web tab make sure that the "User Visual Studio Development Server" option is selected and the "Auto-assign Port" option is not selected. Rather select "Specific Port" and use 8001 to match your configuration
The <baseAddresses> configuration is only for self-hosted services + applications, and is not used by IIS / WAS.
Where you 'put' the .svc on your web server / site defines its url, unless you are using a feature such as file-less activation (article here)
Your IIS url will be something like
http://localhost:8001/MyApp/TestService.svc?wsdl
I'm not sure why WCF test client is defaulting to the wrong URL - just type in the correct one and it will cache it.

net.tcp hosted in IIS7.5 on windows 7 virtual machine using .NET 4.0

I have the simplest WCF service which works when hosted in IIS using basicHttp binding. It has one empty method called DoNothing which takes no parameters and returns a void
void DoNothing()
However I cannot get it to work when trying to host it in IIS using net.tcp.
I am assuming it is the configuration, as the same service code should work regardless of binding used.
I have enabled non-http activation. I am using a different port 12345 to avoid any clashes. The website and service is set up to use net.tcp binding.
The Net.Tcp ListenerAdaptor and Net.Tcp Port Sharing services are running
I can get the metadata to use WcfTestClient to test the service.
The error I get is
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.8597984'.
The inner exception is
An existing connection was forcibly closed by the remote host
I thing I have checked everything. I have tried calling it remotely and locally on the virtual machine
I can only think it is a simple config error or a security issue. The virtual machine is not in a domain. I have disabled the firewall completely on the virtual machine.
Has anyone had the same issue, and has a resolution. Or does someone have a very simple (full) example of how to host a net.tcp service in IIS, whih they could post
Here is my web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="PortSharingBinding" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="SimpleNetTcpService.Service">
<endpoint address="net.tcp://192.168.0.2:12345/SimpleNetTcpService/Service"
binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="SimpleNetTcpService.IService" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I found the issue. I just removed the address attribute from the service element
was
<service name="SimpleNetTcpService.Service">
<endpoint address="net.tcp://192.168.0.2:12345/SimpleNetTcpService/Service"
binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="SimpleNetTcpService.IService" />
now
<service name="SimpleNetTcpService.Service">
<endpoint
binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="SimpleNetTcpService.IService" />
Works fine now