Friday, May 04, 2012 11:40 PM
I have a WCF service that is working with Silverlight. I want to convert this service to WCF REST so that it works with HTML5.
Is there a way to have two bindings for this service so that it can work with both Silverlight and HTML5? Or Do I need to have two separate services for this purpose?
Saturday, May 05, 2012 3:10 PMModerator
You can definitely have two endpoints for this service. In addition to the one you already have, you can add another endpoint for the same contract, using the webHttpBinding / webHttpBehavior. You can even add the [WebGet] / [WebInvoke] attributes in addition to the the [OperationContract] in the operations of your service - they will be ignored by the "normal" endpoint, and used by the REST endpoint. The config below shows one example of how to add another endpoint to the one added by the "Silverlight-Enabled WCF Service" item template.
<system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="Web"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <bindings> <customBinding> <binding name="SLApp.Web.Service1.customBinding0"> <binaryMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <services> <service name="SLApp.Web.Service1"> <endpoint address="" binding="customBinding" bindingConfiguration="SLApp.Web.Service1.customBinding0" contract="SLApp.Web.Service1" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <endpoint address="rest" binding="webHttpBinding" contract="SLApp.Web.Service1" behaviorConfiguration="Web" /> </service> </services> </system.serviceModel>
Wednesday, May 09, 2012 12:14 AMCarlos,
Thanks. My service now has two endpoints and my Silverlight client application works perfectly without any issues.
When I open my service in the IE, I am getting HTTP 400 bad request. It looks like REST part of my service has some issue.
Appreciate any help!
- Edited by codematrix Wednesday, May 09, 2012 12:39 AM
Wednesday, May 09, 2012 1:54 PMModeratorYou'll need to enable tracing at the server to find out why the server is rejecting the REST request. The traces should have an exception indicating the reason.
- Edited by CarlosFigueiraMicrosoft Employee, Moderator Wednesday, May 09, 2012 7:08 PM
Wednesday, May 09, 2012 8:54 PM
Thanks, the log file is created. The file has an exception and here is the message. 'There is a problem with the XML that was received from the network. See inner exception for more details'. Here is the stack trace.
System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Please let me know what to look for.
Wednesday, May 09, 2012 8:56 PMModeratorCan you post the contract and the request which is being sent?
Wednesday, May 09, 2012 9:00 PM
Here is the request.
Wednesday, May 09, 2012 9:02 PMModeratorAnd the contract? Also, the endpoint address you specified for the rest endpoint in web.config is "rest", so the endpoint address should start at .../WCF/Authentication/AuthenticationService.svc/rest.
Wednesday, May 09, 2012 9:04 PM
That's it. I missed "rest". This fixed the issue.