C# - First attempt with WCF in VS2008

Question!

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
    {
        [OperationContract]
        public string Decrypt(string interactive)
        {
            return RivWorks.Security.Cryptography.Internal.Decrypt(interactive);
        }

        [OperationContract]
        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:

<body>
    <form id="form1" runat="server">
        <h1>Greeting</h1>
        <div>
            <asp:Literal id="PutFrameHere" runat="server" />
        </div>
        <hr />
        <asp:ScriptManager ID="SM1" runat="server">
            <Services>
                <asp:ServiceReference Path="~/Services/PlayerService.svc" />
            </Services>
        </asp:ScriptManager>
        <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());
            }
        </script>
        Enter encrypted string:<input type="text" id="encryptedText" />
        <br />
        <input type="button" value="Decrypt" onclick="OnDecrypt()"? />
    </form>
</body>

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:

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

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#" 
                Debug="true" 
                Service="RivWorks.Web.Services.PlayerService" 
                CodeBehind="PlayerService.svc.cs" %>

Not quite a match...



Answers

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....

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

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" 
         behaviorConfiguration="AjaxRestServiceBehavior">
By : marc_s


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