I have a WCF Service hosted in IIS with BasicHttpBinding.
WCF is available through IIS and is routed to an internal HTTP Port with IIS Reverse Proxy (AAR).
When I want to embed the WCF in VisualStudio from my IIS then I can't add the Service Reference and get this error:
The removeserver has returned an error: (415) Cannot process
the message because the content type 'application/soap+xml;
charset=utf-8' was not the expected type 'text/xml;
charset=utf-8'..HTTP GET Error URI:
http://myServer/WebServices/WCF_mywebapi/Service.svc
However if I disable the IIS ARR Reverse proxy (and Host WCF directly on Port 80) then there is no Error.
Is there a problem with ReverseProxy handling my Request?
How can I debug them?
I have some other WebServices on WsHttpBinding and they work well on retriving metadata.
The web.config must be right because I can embed the wervice without active ARR.
I know that there are a few solutions to this error but none of them mention the AAR Module as source.
Can you help me?
Edit: Here whe web.config from WCF:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.1">
<assemblies>
<add assembly="Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5.1"/>
</system.web>
<system.serviceModel>
<services>
<service name="WcfNamespaces.Service.svc">
<endpoint address="Service.svc" bindingNamespace="" binding="basicHttpBinding" bindingConfiguration="" contract="WcfNamespaces.IService"/>
<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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
My Server Config for Proxy:
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://127.0.0.1:1010/{R:1}" />
</rule>
And I disabled svc ISAPI module for IIS Proxy Instance (because the're handled by IIS Instance on other port):
<handlers>
<remove name="svc-ISAPI-4.0_64bit" />
<remove name="svc-ISAPI-4.0_32bit" />
<remove name="svc-Integrated-4.0" />
</handlers>
Thanks :)
Related
I created a web service using Visual Studio 2017 that is hosted on a remote machine (a remote server) using IIS with .NET V4.5.
The web service publishing to IIS was done using IIS Manager.
I am not able to change the "IP address" to something else than "All Unassigned". If I select the IP address available on the drop down menu, then the web site doesn't work (returning error: "HTTP Error 404. The requested resource is not found.").
If I use "All Unassigned" with "host name" "localhost", it works well locally.
Which means that I can enter the url (http://localhost:81/RestServiceImpl.svc) in a web browser and it execute the web service as expected.
My question is: how can I host my web service on this remote machine so that I can then access it from any computer using the url where localhost would be replaced by the remote machine IP address?
See below my web.config file (it could be that I'm not using the right binding, or that the remote machine IP address is hidden):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="RsConnString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|RestDB.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
<!--
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.
-->
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- 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>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<handlers>
<remove name="svc-Integrated" />
<add name=".svc" verb="*" path="*.svc" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory,
System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
/>
</handlers>
<!--
<modules runAllManagedModulesForAllRequests="true"/>
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<modules>
<remove name="ServiceModel" />
</modules>
<directoryBrowse enabled="true"/>
</system.webServer>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
I've been facing a tough issue for three days. I have a WCF web api (.svc service file) deployed to an IIS 8.5. The application was working properly and then, suddenly, after I changed some other minor things inside the code, this problem arises: I can connect to the application from inside the server (using localhost). I can connect from outside, using the server IP address. But I cannot, by any means, connect from the outside by using server hostname. The problem is best understood through the examples bellow:
Note: the application is an IIS app inside the main Web Site. The service's URI is http://myhostname/api/servicos.svc
http://localhost/api/servico/some_request: works!
http://server_ip_address/api/servico/some_request: works!
http://myhostname.com/api/servico/some_request: DOES NOT WORK!
I have searched through many websites and forums but of no avail.
My web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<customErrors mode="Off" />
</system.web>
<connectionStrings>
<!-- My connection string goes here -->
</connectionStrings>
<system.serviceModel>
<services>
<service name="ServicoWeb.servico" behaviorConfiguration="Wcf_Behavior">
<endpoint name="" binding="webHttpBinding" contract="ServicoWeb.IServico" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp automaticFormatSelectionEnabled="true" defaultBodyStyle="Bare" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Wcf_Behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="removeSvcDaUrl" type="ServicoWeb.Validacao.UrlCustomizacao, ServicoWeb" />
</modules>
<directoryBrowse enabled="true" />
<rewrite>
<rules>
<remove name="WordPress: https://myhostname.com" />
</rules>
</rewrite>
<handlers accessPolicy="Read, Execute, Script" />
<security>
<requestFiltering>
<verbs>
<add verb="*" allowed="true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
</configuration>
The error I am presented to when trying to access the API from outside (via hostname) is this:
Server Error in '/Api' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /Api/servico.svc/asos/csv/09655055000104
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.6.1069.1
Do you have any idea what should I do in order to fix this bug?
Edit: one more information: other apps inside the same web site in IIS works FINE! There are even other web apis written in C#, just like this one here, and they all work properly.
Edit 2: another thing important to say is that I can access the service path until the service itself (servico.svc). So, for example, when I try to access "http://myhostname.com/api/servico.svc?wsdl" I successfully get the service's metadata. So, only when I try to access the service itself I get the error mentioned above.
There is a file named host file. When you try request a DN windows look into that file. That file inside C:\WINDOWS\System32\drivers\etc there is host file. Append like below this in your host file (with admin mode).
server_ip_address myhostname.com
I finally got it solved! For those struggling with this issue without sucess: Amazon EC2 load balance was the cause of my troubles.
It happened that Load Balance was set up to filter all requests and send them to the server machines using transport layer SSL security protocol (HTTPS). So, if I were to request http://myserver.com/servico Amazon Load Balance would internally redirect to https://machine-n/servico where 'n' is the machine used (in my case, I have two machines).
So, what caused my issue, inside WCF, was this: my web.config was not allowing the service to accept HTTPS requests. Once I fixed this, everything worked fine.
It also explains why everything worked when I requested directly using the machine's IP address using HTTP: load balance did not play any role in this case filtering the request and redireting using HTTPS.
So, here we have my web.config, now allowing HTTPS requests:
<?xml version="1.0" encoding="UTF-8"?>
...
<system.serviceModel>
<services>
<service name="ServicoWeb.servico" behaviorConfiguration="Wcf_Behavior">
<endpoint name="" binding="webHttpBinding" contract="IServico" bindingConfiguration="webHttpTransportSecurity" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp automaticFormatSelectionEnabled="true" defaultBodyStyle="Bare" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Wcf_Behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
...
In my case below things helped :
Check protocolMapping is binded correctly.
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
Check 443 port is open and working.
I can normally run the application on the emulator and do some action before, but for some reason this suddenly appeared even though the webservice runs properly on the browser.
I looked for a solution with similar case as this but I can't seem to figure out how to do it because I am using Xamarin which has a different way of adding service reference.
Here are my codes:
ServiceReferences.ClientConfig
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFSREmployee" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:51678/FSREmployee.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IFSREmployee" contract="IFSREmployee"
name="BasicHttpBinding_IFSREmployee" />
</client>
<extensions />
</system.serviceModel>
</configuration>
Web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="SQL_HCMConnectionString" connectionString="Data Source=ADGTAPPS5;Initial Catalog=SQL_HCM;User ID=hcm;Encrypt=False;TrustServerCertificate=True"
providerName="System.Data.SqlClient" />
<add name="OFFICEConnectionString" connectionString="Data Source=ADGTAPPS5;Initial Catalog=OFFICE;User ID=office;Encrypt=False;TrustServerCertificate=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
Which emulator are you using it might be the problem of your emulator. Use genymotion emulator it is the works smooth without any problems. And a service hosted on localhost can be accessed through a proxy or with the IP.
Already solved by creating a webservice again and now it is working properly.
I tried to find web.config for my WCF service connect to server using REST call. However, its saying unable to connect server. Here is my web.config:
<?xml version="1.0"?>
<configuration>
<!--<system.net>
<defaultProxy useDefaultCredentials="true" >
</defaultProxy>
</system.net>-->
<appSettings>
<add key="UserName" value="admin"/>
<add key="Password" value="admin"/>
<add key="resturl" value="https://Clientname.atlassian.net/rest/api/2/"/>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IJiraService"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:19065/JiraService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IJiraService" contract="ServiceReference1.IJiraService"
name="BasicHttpBinding_IJiraService" />
</client>
<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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Could anyone please help me, how can I correct this? I tried on net, however, not able to find any suitable tutorial for this. Please help.
This is resolved. Its was a proxy issue and after adding proxy to browser and IIS the issue got resolved. Thanks.
When running the WCF test client and debugging the WCF service locally, everything works fine. After I deploy it to IIS on a remote server and then try loading it with the WCF test client I start getting "Object not set to an instance of object" errors. I added a try-catch to the service and the error changed to "Method not allowed".
I have been reading up on these errors all day and most posts relate to people using JSON or AJAX to access their WCF client. I have tried many of the suggested solutions, most of which were changes to web.config. I am simply accessing it using the test client at this stage, it will be consumed by a Winform application once proven to work.
The 2 methods exposed on the service both create connections to a SQL server on a different domain, although there is a trust set up. I am thinking this could be part of the problem.
My Service Interface
[ServiceContract]
public interface IMeterQueryService
{
[OperationContract]
List<Meter> FindMeter(string mprn);
Implemented Service
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class MeterQueryService : IMeterQueryService
{
public List<Meter> FindMeter(string mprn)
{
using (var da = new DataAccess())
{
var meters = da.GetMeter(mprn);
da.Dispose();
return meters;
}
}
App Config File
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<connectionStrings>
<add name="Tims" connectionString="hidden" providerName="System.Data.SqlClient"/>
</connectionStrings>
<!-- 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="TimsAPI.MeterQueryService">
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false 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="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
web config file, site references the WCF service library.
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="TimsAPI.MeterQueryService">
<endpoint address="http://easvr33:1000/" binding="basicHttpContextBinding" bindingConfiguration=""
contract="TimsAPI.IMeterQueryService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="localhost" />
</baseAddresses>
</host>
</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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Update
I recreated the WCF service as a WCF Service website, rather than a library and it all works now. Something weird between the 2 config files I think. I would still be interested to know why it never worked but I do also understand it may be hard to diagnose for someone without full access to the source
When a WCF service is hosted via an IIS website the service app.config is not used and instead the hosing site's web.config is loaded. All settings needed for the service to work must be duplicated to the web.config of the hosting site.
Might be an issue with serving the SVC to begin with. From here:
1.Open your Virtual Directory’s Properties.
2.Go to the Directory tab.
3.Click Configuration.
4.Click Add…
5.Provide the following information:
a.Executable: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
b.Extension: .svc
c.Verbs: GET,HEAD,POST,DEBUG