C# - First attempt with WCF in VS2008


I am writing my first SVC and am missing something. It all compiles fine but the page does not seem to return anything from my service.

Service Code:

namespace RivWorks.Web.Services
    [ServiceContract(Namespace = "http://www.rivworks.com/ws/")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class PlayerService
        public string Decrypt(string interactive)
            return RivWorks.Security.Cryptography.Internal.Decrypt(interactive);

        public void LogEvent(Int64 HistoryRequestID, string VideoPath, string Action, string Target, string ClientDateTime, string UrlReferrer, float Offset, string TimeZone)
            DateTimeOffset dt = RivWorks.DateTimeInfo.ConvertFromFlash(ClientDateTime);
            RivWorks.Membership.UserInfo userInfo = RivWorks.DateTimeInfo.GetUserInfo(dt, Offset, TimeZone, "Log Request");
            RivWorks.Data.Player.LogEvent(HistoryRequestID, VideoPath, Action, Target, userInfo, UrlReferrer);

My ASPX code:

    <form id="form1" runat="server">
            <asp:Literal id="PutFrameHere" runat="server" />
        <hr />
        <asp:ScriptManager ID="SM1" runat="server">
                <asp:ServiceReference Path="~/Services/PlayerService.svc" />
        <script type="text/javascript">
            function OnDecrypt(result) {
                www.rivworks.com.ws.PlayerService.Decrypt($get("encryptedText").value, OnDecryptComplete, OnError, null);
            function OnDecryptComplete(result) {
                alert("Complete:  " + result.toString());
            function OnError(result) {
                alert("Error:  " + result.toString());
        Enter encrypted string:<input type="text" id="encryptedText" />
        <br />
        <input type="button" value="Decrypt" onclick="OnDecrypt()"? />

When I click the button, nothing appears to happen. I would expect an error or a string in response. Using FireBug and ServiceCapture do not reveal anything. ServiceCapture does not show any requests coming out.

On a slightly different note - what would I need to do to let a Flash and/or Flex app call into the service correctly? I don't do either so am curious as to what the command should look like (to give our flash/flex developers a sample to work from.)

Any hints, tips, tricks?

Forgot to say that I was using a tutorial found at http://www.pluralsight.com/community/blogs/fritz/archive/2008/01/31/50121.aspx

From my web.config:

    <behavior name="RivWorks.Web.Services.PlayerServiceAspNetAjaxBehavior">
     <enableWebScript />
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
   <service name="RivWorks.Web.Services.PlayerService">
    <endpoint address="" behaviorConfiguration="RivWorks.Web.Services.PlayerServiceAspNetAjaxBehavior"
     binding="webHttpBinding" contract="RivWorks.Web.Services.PlayerService" />

Forgive me - I am not exactly clear on what your were looking for. I also dropped out the sections that did not change when I added WCF.

<%@ ServiceHost Language="C#" 
                CodeBehind="PlayerService.svc.cs" %>

Not quite a match...


Can you show us your service config?? What binding are you using? basicHttp, or webHttp (REST)?

By default, if you're using a SOAP service in WCF, when you navigate to the *.svc file's URL location, you don't get much - a page saying a service has been found - that's about it. That's by design.

You can enable metadata on SOAP services (based on WSDL/XSD) - but you need to explicitly do that - dosen't happen by default.

UPDATE: by "service config" I mean everything in your web.config that's inside the <system.serviceModel> section - that's the WCF section.

You're using the webHttpBinding for a REST webservice - you'll need add the "webHttp" behavior to your service behavior, I think. I'm not very familiar with REST and Ajax, so that's a bit unchartered territory for me....

    <behavior name="RivWorks.Web.Services.PlayerServiceAspNetAjaxBehavior">
     <webHttp />
     <enableWebScript />
    <behavior name="AjaxRestServiceBehavior">
     <webHttp />

Can you try to add the <webHttp /> to your web.config, and then reference it from your service declaration:

<service name="RivWorks.Web.Services.PlayerService" 
By : marc_s

This video can help you solving your question :)
By: admin