Hosting a React site in the same folder as a WCF Service - reactjs

I've got an existing WCF service set up on a shared Windows host through GoDaddy, and I'm looking to upload a react app to the same hosting to consume the service.
So, for example, I have the service set up at https://example.com/Service1.svc/ and when you enter https://example.com I want the react app to be visible, and still able to access the service via the existing url.
I'm not sure how to configure my web.config to fulfil this requirement. Navigating to the root domain will give me a 404 error, as will attempting to navigate to index.html, despite the file existing. If I clear out my web.config, the react site will work correctly, but obviously the service no longer works.
Below is my web config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<trust level="Full" originUrl="" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000" />
</webServices>
</scripting>
</system.web.extensions>
<system.serviceModel>
<services>
<service name="MyService.Service1" behaviorConfiguration="web">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="httpBinding"
contract="MyService.IService1" />
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="httpsBinding"
contract="MyService.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="web">
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true" defaultBodyStyle="Bare" faultExceptionEnabled="true"
automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="httpBinding">
<security mode="None" />
</binding>
<binding name="httpsBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
<staticContent>
<clear />
<mimeMap fileExtension="." mimeType="*/*" />
<mimeMap fileExtension=".txt" mimeType="*/*" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
Alternatively, I have found that I can put the service in a subfolder and configure a virtual directory so that it works there, however that changes the URL of the service to http://example.com/subfolder/Service1.svc which is undesirable at this stage. Is there any way I can have the original URL somehow point to the service in the subfolder somehow?
Any help would be appreciated.

I think I figured it out. At first, I thought it was something to do with some configuration in the service blocking everything else, and as it turns out I was almost right, except it had nothing to do with the service itself and everything to do with this section of the web.config:
<staticContent>
<clear />
<mimeMap fileExtension="." mimeType="*/*" />
<mimeMap fileExtension=".txt" mimeType="*/*" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
Specifically, that <clear /> line clears out the existing content handlers, so the server couldn't even serve the HTML and js files that make up the react site.

Related

Trouble with endpoints of my wcf

My WCF service web.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ZesdaagseResultsContext" connectionString="Data Source=194.33.112.88\partywhere;Initial Catalog=ZesdaagseResults;Persist Security Info=True;User ID=*********;Password=******************/;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.serviceModel>
<services>
<service name="WcfOpzet.MobileService" behaviorConfiguration="MexBehavior">
<endpoint binding="webHttpBinding" contract="WcfOpzet.IMobileService" behaviorConfiguration="webHttpBehavior" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MexBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<system.web>
<compilation debug="true" />
</system.web>
</configuration>
My wcf client MobileServiceReference.ClientConfig.
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="webHttpBinding"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://zesdaagse.mobi-app.be/WCFUrl/MobileService.svc"
binding="basicHttpBinding"
bindingConfiguration="webHttpBinding"
contract="MobileService.IMobileService"
name="webHttpBinding"
/>
</client>
<!--<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>-->
</system.serviceModel>
</configuration>
My Error when I run my Windows Phone Application.
There was no endpoint listening at http://zesdaagse.mobi-app.be/WCFUrl/MobileService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Explanation
I searched but I don't get it fixed. There is something wrong with my endpoints but I don't know what.
Ah, now I see it
You are using the basicHttpBinding in your client and the webHttpBinding (REST) in your service... That's probably the reason why it's not working, no?
Extra FYI: I tried to call your service myself and now I get a 405, which probably means you didn't specify the [WebGet] or [WebInvoke] attributes to your service operations.
With the following client side config, you should be able to call your service (after attributing your operations with WebGet)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://zesdaagse.mobi-app.be/WCFUrl/MobileService.svc"
binding="webHttpBinding"
bindingConfiguration="webHttpBinding"
contract="MobileService.IMobileService"
name="webHttpBinding"
behaviorConfiguration="webHttpBehavior"
/>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

Silverlight - How to consume a WCF service from the client with windows authentication

I have a silverlight 4 application and I need the client to consume a WCF service secured with SSL and using windows authentication. Only members of a certain active directory group should be able to call the WCF service.
Here is my web.config. With the current configuration anyone can call the WCF service. what should be the correct values?
Thanks,
Kruvi
<configuration>
<system.diagnostics>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="On" defaultRedirect="~\Errors\Error.htm">
<error statusCode="404" redirect="~\Errors\404.htm"/>
</customErrors>
</system.web>
<connectionStrings>
</connectionStrings>
<system.serviceModel>
<diagnostics>
</diagnostics>
<extensions>
<behaviorExtensions>
<add name="silverlightFaults"
type="ZCUtils.SilverlightFaultBehavior, ZCUtils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ZCBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBindingSsl" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
<services>
<service name="ZC.Web.Services.ZCServices" behaviorConfiguration="ZCBehavior">
<endpoint address="" behaviorConfiguration="SilverlightFaultBehavior"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBindingSsl"
contract="ZC.Web.Services.ZCServices" />
</service>
</services>
</system.serviceModel>
</configuration>
The following article shows how to secure a WCF service with Windows auth for Silverlight clients:
http://msdn.microsoft.com/en-us/library/dd744835(v=vs.95).aspx
This article talks about using the PrincipalPermissionAttribute, which will allow you to restrict with groups can call a particular service operation:
http://msdn.microsoft.com/en-us/library/ms731200.aspx

Silverlight 4 - Configure Self-Hosted WCF Service to use SSL

I have a Silverlight 4 application that uses WCF services on the same server (self-hosted). Everything works fine, but now I want to convert my WCF services to use SSL. I am using CustomBindings and can't quite find the combination to get this done. I am using relative URLs on the client side, and hope this is not causing a problem. Here are the important bits of my Web.config file:
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<serviceTimeouts transactionTimeout="00:10:00"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="MyApp.Web.Services.ProjectService.customBinding0"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<services>
<service name="MyApp.Web.Services.ProjectService">
<endpoint address="" binding="customBinding" bindingConfiguration="MyApp.Web.Services.ProjectService.customBinding0"
contract="MyApp.Web.Services.ProjectService" />
</service>
My ClientConfig looks like this:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_ProjectService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="../Services/ProjectService.svc" binding="customBinding"
bindingConfiguration="CustomBinding_ProjectService" contract="SearchProxy.ProjectService"
name="CustomBinding_ProjectService" />
</client>
</system.serviceModel>
</configuration>
I just don't understand how the bindings work in both the server and client. I'm hoping someone can point me in the right direction.
A few things:
If you want to use SSL on localhost you'll need to be using IIS Express 7.5 (or full IIS if you're on a server doing dev - unlikely).
You'll need a clientaccesspolicy.xml file stored in the root of the Web application:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers= "SOAPAction">
<domain uri="https://*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Example server-side Web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SecureBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SomeBehavior" >
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="https" port="443" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="SomeService.svc" service="MySilverlight.Web.SomeService"/>
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="MySilverlight.Web.SomeService"
behaviorConfiguration="SomeBehavior">
<endpoint address="SomeService"
binding="basicHttpBinding"
bindingConfiguration="SecureBasicHttpBinding"
bindingNamespace="https://MySilverlight.Web.SomeService"
contract="MySilverlight.Web.ISomeService">
</endpoint>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Example client-side:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISomeService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/SomeService.svc/SomeService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISomeService"
contract="MySilverlight.Web.SomeServiceReference.ISomeService"
name="BasicHttpBinding_ISomeService" />
</client>
<extensions />
</system.serviceModel>
</configuration>
IIS 7.5 will setup your localhost certificate automatically.
Can you update the service reference on the client project? That should update the clientconfig file with the correct binding. One thing I am noticing right now is that you're using <httpTransport> on the client binding and <httpsTransport> on the service. Try changing the client to use <httpsTransport> as well.
Also, if your SL app is downloaded from an HTTP:// address, then a call to a service in HTTPS is considered to be a cross-domain call, so you'll need a cross-domain policy file as well.

Does Silverlight client support WCF behaviors?

I am trying to add a WCF endpoint behavior to my Silverlight client. However I am getting the following error at runtime:
Unrecognized element 'behaviors' in service reference configuration.
Note that only a subset of the Windows Communication Foundation
configuration functionality is available in Silverlight.
Is it really true that WCF endpoints cannot be extended in Silverlight? My ServiceReferences.ClientConfig file is listed below showing how I am trying to add an extention called MyBehaviorExtention:
<configuration>
<system.serviceModel>
<extensions>
<behaviorExtentions>
<add
name="MyBehaviorExtention"
type="MyTest,
MyBehaviorExtention,
Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null" />
</behaviorExtentions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="MyBehavior">
<MyBehaviorExtention />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding
name="MyWebServicePortBinding"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint
name="MyWebServicePort"
address="http://localhost:8080/MyService"
binding="basicHttpBinding"
bindingConfiguration="MyWebServicePortBinding"
contract="MyServiceReference.MyWebService"
behaviorConfiguration="MyBehavior" />
</client>
</system.serviceModel>
</configuration>
Should this not go in your server side web.config instead? The ServiceReferences.ClientConfig should contain information pertaining to WebService Reference information e.g. endpoint address etc. It contains the addresses of the services and it gets compiled inside the .xap file generated by compilation.
Here is a sample of my web.config where I use behaviour extensions:
<extensions>
<behaviorExtensions>
<add name="silverlightFaults" type="MyApp.Web.Services.SilverlightFaultBehavior, MyApp.Web"/>
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
This is all I need. My ServiceRefeferences.ClientConfig only contains endpoint addresses. It only contains a subset of Windows Communication Foundation (WCF) client configuration.

How to configure WCF Service with Https WindowsAuthentication?

I am trying to figure it out how to set configurations on my service and Silverlight client App to work on Secure Windows Authentication.
I have my service configured like this:
<binding name="currentCustomBinding">
<binaryMessageEncoding />
<httpsTransport authenticationScheme="Ntlm" bypassProxyOnLocal="true" />
</binding>
</customBinding>
<serviceMetadata httpGetEnabled="False" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<service name=" OperationService" behaviorConfiguration=" OperationServiceBehavior">
<endpoint address="" behaviorConfiguration=" OperationServiceBehavior" binding="customBinding" bindingConfiguration="currentCustomBinding" contract="OperationService" />
</service>
Any ideas? 10q

Resources