Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the followings:

In Competitions.svc:
XML
<%@ ServiceHost Language="C#" Debug="true" Service="MySite_WebSite.Pages.Client.CompetitionsSVC" CodeBehind="Competitions.svc.cs" %>


In ICompetitions.cs :
C#
namespace MySite_WebSite.Pages.Client
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICompetitions" in both code and config file together.
    [ServiceContract(Name="CompetitionsSVC")]
    public interface ICompetitions
    {
        [OperationContract]
        [WebInvoke(
            Method = "GET"
            , RequestFormat = WebMessageFormat.Json
            , ResponseFormat = WebMessageFormat.Json
            , UriTemplate = "DoWork"
            , BodyStyle=WebMessageBodyStyle.Wrapped
        )]
        Dictionary<DateTime, List<Competitions.Entry>> DoWork();
    }
}


In Competitions.svc.cs :
C#
namespace MySite_WebSite.Pages.Client
{
    [DataContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class CompetitionsSVC : ICompetitions
    {
        #region ICompetitions Members

        public Dictionary<DateTime, List<Competitions.Entry>> DoWork()
        {
            var c = new Competitions();

            return c.GetMonthlyEntries(new Competitions.ParamGetMonthlyEntries()
            {
                Start = DateTime.Now.Date.AddMonths(-1)
                , End = DateTime.Now.Date.AddMonths(2)
                , UserLang = "fr-BE"
                , ActiveLang = "fr-BE"
                , IsExternal = false
            });
        }

        #endregion
    }
}


In Web.config:

XML
<system.serviceModel>
  <services>
    <service name="MySite_WebSite.WS.WCF.SubsetMID">
      <endpoint address=""
                binding="wsHttpBinding"
                contract="MySite_WebSite.WS.WCF.ISubsetMID" />

      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
    <service name="MySite_WebSite.Pages.Client.CompetitionsSVC">
      <endpoint address=""
                binding="webHttpBinding"
                behaviorConfiguration="WebBehavior"
                contract="MySite_WebSite.Pages.Client.ICompetitions" />

      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
  </services>
  <bindings>
    <wsHttpBinding>
      <binding>
        <security mode="None"/>
      </binding>
    </wsHttpBinding>
    <netTcpBinding>
      <binding name="NetTcpBinding_IServiceWCallBack" sendTimeout="00:10:00"
        maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
        <readerQuotas maxStringContentLength="2147483647" />
        <security mode="None" />
      </binding>
      <binding name="NetTcpBinding_IHandleSubset">
        <security mode="None" />
      </binding>
    </netTcpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true" />
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="WebBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment
      multipleSiteBindingsEnabled="true"
      aspNetCompatibilityEnabled="true"
  />
</system.serviceModel>



When I enter the url
localhost2/MySite_WebSite/Pages/Client/Competitions.svc/DoWork
, it doesn't work.
I have a breakpoint at the begining of the method, and I can see the method gets called twice, yet it doesn't return anything (I don't even think it send any HTTP code backs).

What did I do wrong?
Posted
Comments
BELGIUMsky 17-Apr-14 10:29am    
EDIT: have posted this as a solution because it looks like i can't use the code tags in a comment

This is not a solution but it looks like i can't show code in a comment so this was the way i thought was best to show my question.

are you sure your code:
C#
return c.GetMonthlyEntries(new Competitions.ParamGetMonthlyEntries()
{
   Start = DateTime.Now.Date.AddMonths(-1)
    , End = DateTime.Now.Date.AddMonths(2)
    , UserLang = "fr-BE"
    , ActiveLang = "fr-BE"
    , IsExternal = false
});


returns a value?

if that returns null its normal that you don't see anything.

can you try to do something like:
C#
Dictionary<datetime,>> dictionaryList = c.GetMonthlyEntries(new Competitions.ParamGetMonthlyEntries()
{
   Start = DateTime.Now.Date.AddMonths(-1)
    , End = DateTime.Now.Date.AddMonths(2)
    , UserLang = "fr-BE"
    , ActiveLang = "fr-BE"
    , IsExternal = false
});

return dictionaryList;


put a break point on that return statement.
and when the program stops check if dictionaryList is not null or empty
 
Share this answer
 
Ok, I solved the problem.

I use a custom piece of code to serialize the dictionnry into a JSON string and I don't use DateTime objects as keys anymore (as those aren't valid keys for a JSON dictionary).

C#
public Stream Test()
{
    var c = new Competitions();
    var result = c.GetMonthlyEntries(new Competitions.ParamGetMonthlyEntries()
    {
        Start = DateTime.Now.Date.AddMonths(-1)
        , End = DateTime.Now.Date.AddMonths(2)
        , UserLang = "fr-BE"
        , ActiveLang = "fr-BE"
        , IsExternal = false
    }).ToDictionary(
        kp => kp.Key.ToString("yyyy-MM-dd")
        , kp => kp.Value
    );

    var javaScriptSerializer = new JavaScriptSerializer();
    var json = Encoding.UTF8.GetBytes(javaScriptSerializer.Serialize(result));
    var memoryStream = new MemoryStream(json);
    WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
    return memoryStream;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900