I have looked through all of the other solutions and none of them are working. I am hosting a WCF service using IIS. The following is my web.config (the default for when I added a WCF service):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
All is good and I can access my wcf service in the browser using http://www.domain.com/path/service.svc and https://www.domain.com/path/service.svc - now I add a web reference to https://www.domain.com/path/service.svc in a windows console application and the following is in my app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="defaultBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://www.domain.com/path/service.svc" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding" contract="DomainExt.IExt" name="BasicHttpBinding_IExt" />
</client>
</system.serviceModel>
</configuration>
The following code is what I am using to test the service:
public static String DoPing()
{
ExtClient client = new ExtClient("BasicHttpBinding_IExt", "https://www.domain.com/path/service.svc");
return client.DoPing();
}
After I run this I get the following exception:
There was no endpoint listening at https://www.domain.com/path/service.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 inner-exception sates:
"The remote server returned an error: (404) Not Found."
This service works fine over http but fails on https. How can I fix this? Please note that I'm accessing this service using Windows Console and NOT through ASP.NET; ASP.NET is only hosting the WCF service.
Try setting httpsGetEnabled="true" rather than httpGetEnabled
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" />
EDIT: I'm also curious why you chose the BasicHttpBinding if you're using SSL. Why not use the WsHttpBinding?
EDIT2: Are you missing a <services> node in your host config file? I wouldn't think you could create a client without one. You can right click on your app.config file and configure it there... Something like this:
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint address="" binding="defaultBasicHttpBinding" bindingConfiguration="basicBinding" contract="IMyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
Related
I'm trying to host a WCF REST service on an https server. The IIS manager on the server is configured property for the https port and my Web.config is configured properly. But, I just get this message "Server Error in '/' Application error" when pinging the URL. The URL matches the correct virtual directory which has been configured as an IIS application. It just doesn't resolve. I have another WCF service on this server that's running fine, but it's using basicHttpBinding since it's a soap service.
Can someone look at my RESTful web.Config and see if I've over looked something since there must be something wrong? This service works fine when deployed on my local machine using http without all the https config settings, but when deployed on another https server it doesn't work. There has to be something I'm missing. Tnx.
<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<!-- SQL connection settings -->
<connectionStrings>
</connectionStrings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.6" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.6"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<client/>
<bindings>
<webHttpBinding>
<binding name="secureHttpBinding" maxReceivedMessageSize="200000000">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
<mexHttpsBinding>
<binding name="secureMexBinding"/>
</mexHttpsBinding>
</bindings>
<behaviors>
<!-- Required for json web service -->
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehaviors">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="false" 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>
<services>
<service behaviorConfiguration="serviceBehaviors" name="RepoWebService.MasterRepoAPI">
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="secureHttpBinding" contract="StatuteRepoWebService.IRepoWebService.MasterRepoAPI"/>
<endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration="secureMexBinding" contract="IMetadataExchange"/>
</service>
</services>
<protocolMapping>
<add scheme="https" binding="webHttpBinding" bindingConfiguration="secureHttpBinding"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
There is no problem your service configuration file seems to me. It only supports Https protocol. There might some problems in the hosting environment.
we are supposed to provide a https binding in IIS binding module, then service address will be https://x.x.x.x:xxxxx/service1.svc
Besides, here is my simplified configuration which using the WCF4.5 new feature, Protocol Mapping. it supports both https and http.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="mybinding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="webHttpBinding" scheme="http"/>
<add binding="webHttpBinding" scheme="https" bindingConfiguration="mybinding"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
https://learn.microsoft.com/en-us/dotnet/framework/wcf/whats-new
Feel free to let me know if there is anything I can help with.
I've built a WCF service that is hosted on a server by a windows service. Everything works fine and i have already tested some method. Now i need to send an httprequest from my client like this one:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(String.Format(#"http://192.168.0.170:9001/myServ/Start/{0}/{1}", "blabla", "blabla"));
req.Method = "GET";
The problem is that i keep getting an exception on client side stating that my request is invalid. I can't understand why.
This is my wcf service:
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "Start/{param1}/{param2}")]
string Mod(string param1, string param2);
Here is my configuration
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- 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>
<bindings>
<webHttpBinding>
<binding maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed"
sendTimeout="00:05:00"
name="WebHttpBinding_InotifyImp">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="wcfImp.notifyImp" behaviorConfiguration="NewBehavior">
<endpoint address="" behaviorConfiguration="DefaultEndPointBehavior" bindingConfiguration="WebHttpBinding_InotifyImp" binding="webHttpBinding" contract="wcfImp.InotifyImp">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/notifyImp"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<!-- 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>
<endpointBehaviors>
<behavior name="DefaultEndPointBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
I found the problem. I was hosting my WCF service in debug mode using visual studio 2015 to check the various step of my process. I don't know why, but while i didn't have any problem with the other method, the handler associated to the get method, have an assembly that couldn't be loaded. I tried to host the service on windows service and everything worked fine
I have imported an a wcf service and it is accessible from local host but when I use my public ip address i am unable to reach it.
This is the contents of my web.config file.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"
targetFramework="4.0" />
</system.web>
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="clearUsernameBinding"
type="WebServices20.BindingExtenions.ClearUsernameCollectionElement, ClearUsernameBinding" />
</bindingExtensions>
<!-- Add the inspector attribute as a behavior for displaying SOAP XML packets -->
<behaviorExtensions>
<add name="consoleOutputBehavior"
type="WcfService1.ConsoleOutputBehaviorExtensionElement, WcfService1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<bindings>
<clearUsernameBinding>
<binding name="myClearUsernameBinding"
messageVersion="Soap12" />
</clearUsernameBinding>
</bindings>
<behaviors>
<!-- Add the inspector behavior -->
<endpointBehaviors>
<behavior name="inspectorBehavior">
<consoleOutputBehavior />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="HelloWorldServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfService1.CustomUserNameValidator, WcfService1" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="HelloWorldServiceBehavior"
name="WcfService1.HelloWorldService">
<endpoint address=""
binding="clearUsernameBinding"
bindingConfiguration="myClearUsernameBinding"
contract="WcfService1.IHelloWorldService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
I have a console app that is able to communicate with it but ONLY with localhost.
This is how I am able to get to it. It is running on port 14946 and have port forwarded that port to the computer that has the service running. It is hosted on IIS.
http://localhost:14946/HelloWorldService.svc?singleWsd
If I use : {publicIP}:14946/HelloWorldService.svc?singleWsd
I get a 500 internal error which means its a configuration issue but I can't seem to pinpoint what the problem is.
EDIT: I am now receiving this error.
The type 'WcfService1.HelloWorldService', provided as the Service attribute value in the ServiceHost directive could not be found. I am able to get to it over the web now but receiving this error now. In order to fix the previous error I had to: 1.) Go to add remove features 2.) Expand MS .NET Framework 3.) Flip on both HTTP and Non-HTTP activation for WCF
Thanks,
If you properly hosted it in IIS you can just remove the port in endpoint and access it directly, something like this: ( add virtual application if necessary )
http://<public ip>/HelloWorldService.svc?singleWsd
It is working in your localhost because it was hosted in IIS Express upon debug mode and automatically assigned that port.
I'm trying to implement Transport-Level security (using Windows authentication/credentials) via a wsHttpBinding. But I'm getting the following error: Binding validation failed because the WSHttpBinding does not support reliable sessions over transport security (HTTPS). The channel factory or service host could not be opened. Use message security for secure reliable messaging over HTTP.
<?xml version="1.0"?>
<configuration>
<appSettings/>
<system.web>
<roleManager enabled="true" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsSecure">
<reliableSession enabled="true" />
<security mode="Transport">
<transport proxyCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyService">
<endpoint address="https://localhost:8000/MyService/" binding="wsHttpBinding" bindingConfiguration="wsSecure"
name="wsBinding" contract="IMyContract" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I am getting the following error when trying to access a WCF service.
Could not find a base address that matches scheme http for the endpoint with binding MetadataExchangeHttpBinding. Registered base address schemes are [https].
Here's my config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DefaultHttpBinding"
maxBufferSize="655360"
maxReceivedMessageSize="655360">
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://MySite.com/MyVirtualDir/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="DefaultBehavior"
name="MyWcfService">
<endpoint address="http://MySite.com/MyVirtualDir/MyWcfService.svc"
binding="basicHttpBinding"
bindingConfiguration="DefaultHttpBinding"
contract="MyNamespace.IMyWcfService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true"
policyVersion="Policy15"/>
<serviceDebug httpHelpPageEnabled="true"
includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
And here's my .scv file
<%# ServiceHost Language="C#" Debug="true" Service="MyWcfService" Factory="MyWcfServiceHostFactory"%>
To give some more background that may or may not be helpful
The service works fine in our DEV environment. This error is only
occurring in our TEST and PROD environments. The only discernable
difference between environments that i am aware of is that TEST and PROD are using a
load balancer.
The service is hosted in IIS 5.1 on all environments
The service has been written in dot.net 3.5 and is activated by a
WebServiceHost factory
I have not specified https anywhere in my config file
SSL has NOT been enabled in IIS on any of the environments. Anonymous access has been enabled (security implementation will come later on).
Any help would be much appreciated as this is a complete show stopper for our project. I have throurghly searched the web for solutions to this problem, but nothing seems to relate to my my particular set up.
So for me, the fix for this issue was to remove the mex binding as per some of your suggestions. I also removed the servicemetadata section from the DefaultBehavior in config.
This fix only hides the original issue as I still have no idea why the mex binding was registered as https. But I can now consume my web service, even if i can't retrieve the metadata from it - that's not a problem in my case.
Here's the corrected config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DefaultHttpBinding"
maxBufferSize="655360"
maxReceivedMessageSize="655360">
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://MySite.com/MyVirtualDir/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="DefaultBehavior"
name="MyWcfService">
<endpoint address="http://MySite.com/MyVirtualDir/MyWcfService.svc"
binding="basicHttpBinding"
bindingConfiguration="DefaultHttpBinding"
contract="MyNamespace.IMyWcfService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceDebug httpHelpPageEnabled="true"
includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Try enabling tracing on your service to check why things fail in your test/production environment. To enable tracing check this link
Are you sure that the MyWcfServiceHostFactory doesnt have any code related to configuration (i.e. building configuration via c# code)