400 Bad Request (Invalid Host) using WCF and mono - c#

I am getting a Bad Request (Invalid host) when trying to run my C# WCF service under mono. This service is part of an application, not being hosted using a web server.
I have configured my services with the following:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="DefaultServiceBehavior" name="MyServices.TaskService">
<endpoint address="V1" binding="basicHttpBinding" contract="MyServices.ITaskServiceV1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/MyServices/Tasks" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
When I try to visit http://localhost:8731/MyServices/Tasks or any of its endpoints (including ?wsdl), I get the 400 error.
I have deployed this successfully using the .net runtime, just can't figure out what's wrong for deploying with mono. Any help would be greatly appreciated.
EDIT Mono version: 2.10.1

I had the same issue today.
Hosting a wcf service inside a .net 3.5 application worked but same code using mono 3.2.2 gives invalid host error response.
So I checked mono source and found out that mono searches for a valid endpoint from request url using case sensitive compare. Changed my url to fit case like in my service config resolved the issue.

Related

Unable to access to WCF hosted in a windows service

I have a very weird problem with a 3 tiers client/server application with WCF.
First, I have a service windows which host WCF services in basicHttpBinding. This is the server app.config :
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Business.BSServiceManagement" behaviorConfiguration="myServiceBehave">
<host>
<baseAddresses>
<add baseAddress="http://localhost:35001"/>
</baseAddresses>
</host>
<endpoint address="/Clients" binding="basicHttpBinding" name="Clients" contract="Contracts.BusinessFacade.IBFClientManagement"/>
<endpoint address="/Users" binding="basicHttpBinding" name="Users" contract="Contracts.BusinessFacade.IBFUserManagement"/>
<endpoint address="/Licences" binding="basicHttpBinding" name="Licences" contract="Contracts.BusinessFacade.IBFLicenceManagement"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehave">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
This service is deployed on a server in DMZ and I have access from my computer (in firefox, if I put service address with port number)
Secondly, I have a client application made with winforms which consume the service with ChannelFactory.
This is the client app.config :
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://192.168.128.1:35001/Clients" binding="basicHttpBinding" name="Clients" contract="Contracts.BusinessFacade.IBFClientManagement"/>
<endpoint address="http://192.168.128.1:35001/Users" binding="basicHttpBinding" name="Users" contract="Contracts.BusinessFacade.IBFUserManagement"/>
<endpoint address="http://192.168.128.1:35001/Licences" binding="basicHttpBinding" name="Licences" contract="Contracts.BusinessFacade.IBFLicenceManagement"/>
</client>
</system.serviceModel>
</configuration>
When I debug client application, all works perfectly. So I've made a installer project to deploy application on several computers but when I execute exe of application (installed or directly in bin/release), I have an error message like this :
There was no endpoint listening at http://192.168.128.1:35001/Users...
The inner exception says:
Unable to connect to the remote server
I tried adding mex endpoint, change port number, check server and client computer firewall, I don't understand where is the problem.
Thanks for your help.
EDIT 1 :
After several tests I have the same problem in release exe but not in debug exe.
If I execute the debug exe all works fine but the release exe return the error message.
The problem is with your Service.
Make sure that the Service is Started and running.
Once you start the Service, browse URL(eg: localhost:8080/example), just to make sure Service is running fine.
When you add Service Reference to your client Application, it automatically generates endpoints in app.config file.
When you added Installer to client project, make sure that it is builds Successfully.
When you install it, it should work for you.

SQL Server database, wcf and WinForm

I have a sweet WinForm application (on my computer) and a SQL Server database (on server X). I'm using SqlConnection and everything works fine.
But not I want to change it and use WCF or other technologies to connect and switch information between my app and database.
I also have one more server to use as application server (Server Y).
I've started using WCF: created project, created installer.
Uploaded it on my Y server and installed it. Service started, also I've added Service Reference to my WinForm app, but the ServiceClient is not working properly.
When I call ServiceClient's method it throws exception:
An exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll but was not handled in user code
Additional information: There was no endpoint listening at http://localhost:41272/service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
As I guess my endpoint is blowing things up.
So I want you guys help me how to configure SQL endpoint.
Here is my WCF's web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime />
<pages controlRenderingCompatibilityVersion="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SampleSvcBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="SampleSvcBehavior"
name="FMG_WCF.FmgService">
<endpoint name="SampleSvcBasicHttpEndPoint"
address=""
binding="basicHttpBinding" bindingConfiguration=""
contract="FMG_WCF.IFmgService" />
<endpoint name="SampleSvcMexHttpEndPoint"
address="mex"
binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:41272/service" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
This error is not related with SQL endpoint. In facts you do not need endpoints for connecting WCF to database. Here is your answer in another post.
EndpointNotFoundException - 404 - Hosting WCF Service over HTTPS in IIS through Visual Studio
You have two options, if the service has been modified from when you created it you can simply right click on the service reference and configure the service reference. In the popup you can change the Url to point to serverX and you service reference and config file will be automatically updated.
If no changes were made to the service, for example your binding type or security then simply updating the Url in the config file should be enough.

Adding Service Reference to ASP.NET application

I have searched on here for the exact solution to my problem to no avail.
I have added a Web Service to my project but am unable to reference it. Clicking Discover works fine - the service is available but when it comes to retrieving a list of services at its location the following text appears:
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved:
Metadata contains a reference that cannot be resolved:
'http://localhost:57657/Services/AFDiscovery.svc'.
If the service is defined in the current solution, try building the solution and
adding the service reference again.
How do I fix this? I am attempting to run the service locally so I do not need to add it within IIS.
Web.config information:
<services>
<service name="WebServiceInterface.AFDiscovery">
<endpoint address="" binding="wsHttpBinding" contract="WebServiceInterface.AFDiscovery" />
</service>
</services>
You can add the project containing the WebServiceInterface.AFDiscovery in your solution. Then in the project using the web service, when you add your reference, instead of clicking "Discover", use the load from project option.
If you want to load the reference via a URL (Discover button), try browsing to "http://localhost:57657/Services/AFDiscovery.svc?WSDL" in your browser. If you get a message saying the metadata isn't accessible, you must modify your web service web.config.
Check this link for configuring the web.config: http://msdn.microsoft.com/en-us/library/aa751951.aspx
It should look similar to:
<configuration>
<system.serviceModel>
<services>
<service
name="WebServiceInterface.AFDiscovery"
behaviorConfiguration="SimpleServiceBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="WebServiceInterface.IAFDiscovery" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SimpleServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
One of the possibility is the service name in your Web.config does not
match the namespace in your class file.Make sure the names are the
same then try again.
Refer
And double Check your Service MarkUp code by reghclick and Choose MarkUp

Unable Host WCF Service with nettcpBinding on IIS 7.0

I am having a WCF ServiceLibrary which runs successfully on WCF Test Client.
Now I am trying to build a Website to Host this web service. I am using nettcp binding. My web.config file looks like this
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcp_Unsecured" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="tcpServiceBehavior" name="MarketFeedServiceLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcp_Unsecured"
name="data" contract="MarketFeedServiceLibrary.IService1" />
<endpoint address="mextcp" binding="mexTcpBinding" name="metadata"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="tcpServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I am try to view in browser directly from Solution Explorer
But I get error as shown below
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 tried all the solutions available on SO, youtube etc but no luck,
I tried:
Under IIS I have enabled http,net.tcp protocols
I have also gone through: How to: Install and Configure WCF Activation Components
N.B. I am a WPF App Developer, hence WCF and ASP.NET Website are new to me.
Thank You.
Edit: Testing Under WCF Client gives following error
Cannot obtain Metadata from net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.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. WS-Metadata Exchange Error URI: net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc'. Could not connect to net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc. The connection attempt lasted for a time span of 00:00:01.9968000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8080. No connection could be made because the target machine actively refused it 127.0.0.1:8080

Cannot debug wcf-windows service

Our application accesses a WCF service, which is hosted by a Windows Service on a single computer. The client application and service always will be on the same computer.
I've created a Windows Service that hosts a WCF service. To test my Windows Service code, I created a console application that contains the same app.config and code as my Windows Service. I start the console application in one debugging thread, and launch my client in another debugging thread. Everything works perfectly and I can easily use the debugger.
Now the rub...
So, I created an installer and installed my Windows Service. After successfully starting it, I successfully added the Service Reference to my client using http://localhost/VssService within Visual Studio 2010. I successfully attached to the service via "Attach To Process". I launched my client in a debugging thread, but when I try to step into a remote method, I get "Unable to automatically step into the server. The debugger failed to stop in the server process." This happens for both [NetNamedPipeBinding_IVssService] and [BasicHttpBinding_IVssService]. I have been struggling with this for hours and have run out of ideas, so I hope that you can help me. I've included the app.config files for my Windows Service and Client application. Hopefully they will help.
I appreciate your taking time to read this question and hope that you can help be to resolve this problem...
Mike
===================== SERVICE APP.CONFIG =============================
<services>
<service behaviorConfiguration="VssServiceBehavior" name="ClientSaver.VssService.VssService">
<endpoint address="net.pipe://localhost/VssService/Pipe/" binding="netNamedPipeBinding"
bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />
<endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />
<endpoint address="http://localhost/VssService/MEX/" binding="mexHttpBinding"
bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/VssService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VssServiceBehavior">
<serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
========================= CLIENT APP.CONFIG =============================
<endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VssServiceBehavior">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Ok. One way I use when VS debugging stops working is to place a System.Diagnostics.Debugger.Break() in a conventient place in the service code (say, constructor or method). This causes the JIT debugger to fire up and allows me to connect to the service with the code broken at that point with any VS instance I have.
Obviously you remove it from non debugging code.
You can't step across executable boundaries. Youll need to set breakpoint in your server code (that is project). Then from server`s project attach to the running windows service process (be carefull here ... you need to have latest server project running as windows service). Then, when you step in your Windows Forms app, it'll get caught by the server's breakpoint.
You should use internet explorer as default browser to debug your service...
Have a look at the debugging tools for windows. There are a couple of tools in here that are useful for debugging windows services.
Have you tried manually loading debug symbols? It once happened to me and it was happening because VS was not loading the symbols.

Categories