0

I am trying to get ASP.NET (Framework 3.5), AJAX, and JSON to work. I have two questions along those lines. This first is, when I add the below tag as required by ASP.NET:

[AspNetCompatibilityRequirements(RequirementsMode = 
      AspNetCompatibilityRequirementsMode.Allowed)]

I find that I cannot add it above an interface declaration, only a class. I want this code to be an interface. Can somebody tell me what I am doing wrong? The error is as follows:

Attribute AspNetCompatibilityRequirements is not valid on this declaration type. It is only valid on 'class' declarations.

    [ServiceContract(Namespace = "API.Trade")]
    [AspNetCompatibilityRequirements(RequirementsMode = 
        AspNetCompatibilityRequirementsMode.Allowed)]
    public interface ITradeService
    {
        [OperationContract(Name = "GetAllCategories")]
        string GetCategories(string itemtype, string keywordstring);

        [OperationContract(Name = "GetCategoryByNodeLevel")]
        string GetCategories(int NodeLevel); 

        [OperationContract]
        int GetTrades(string KeywordString, string TradeType);
    }

THE SECOND question is, in the ASPX ScriptManager tag:

 <asp:ScriptManager ID="ScriptManager1" runat="server">
 <Services>
 <asp:ServiceReference Path="?" />
 </Services>
 </asp:ScriptManager>

I notice that the Path= attribute should be pointing to a .SVC file. So far, I have successfully been using a WCF Class Library to accomplish what I need. The Class Library has the Trade.cs, TradeService.cs, and ITradeService.cs files which I compile and then reference as my Web Service in my Web project.

So, what should "Path=" be pointing to? Or, what do I need to add?

I am learning as I go and I appreciate your patience. Thanks in advance.

John Saunders
  • 160,644
  • 26
  • 247
  • 397

4 Answers4

0

With respect to the first question. The attribute is defined to be only applicable to a class, so you can't declare it on anything else.

The path should point to the endpoint where your service is listening (e.g. /services/myserivce).

Paul van Brenk
  • 7,450
  • 2
  • 33
  • 38
0

The path ought to be the service endpoint for an HTTP service: http://host.example.com/tradeservice.svc/method.

You can only apply the attribute to an implementation of the interface (a class) not the interface itself.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
0

As for your second answer. I believe the path needs to point to a actual webservice endpoint (.svc or the old one.. I forget off the top my head, sorry).

What you can do is create a WebService, TradeService.svc, and implement the ITradeService interface. As a private variable on the service create a instance of TradeService, and use it as a proxy... like so

private TradeService _proxy;

public string MyMethod(){
    _proxy.MyMethod();
}

make sence.

alanquillin
  • 1,242
  • 2
  • 11
  • 16
  • Hi Aquillin, Thanks for that. I get the gist of what you are saying but am geting caught up with how to expose the interfaces I created in my class library. I am assuming that I need to add a USING directive to ITradeService and then make a reference to the interface methods (MyMethod) in the DLL which I can then use in "_proxy.MyMethod". I am not really sure how to go about this - can you show me what the code should look like for ITradeService after adding the WCF Class Library that I have? I hop I have made sense here... –  Jul 29 '09 at 14:17
0
  • AspNetCompatibilityRequirementsAttribute.RequirementsMode is not a required attribute and can be used for setting the hosting mode programmatically Or you can do the same in webconfig by using serviceHostingEnvironment tag:
    <system.serviceModel> 
    <serviceHostingEnvironment ..>
    </serviceHostingEnvironment>
    </system.serviceModel>

Reference : http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.requirementsmode(v=vs.110).aspx

  • You should add a service host(.svc) in your project by manually adding TradeService.svc. You can also do same by adding new item > WCF Service but that will override your service cs files. Once you have your svc file added then you can add following line:
 
     &lt%@ ServiceHost Language="C#" Debug="true" Service="TradeService" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>

Note that WebScriptServiceHostFactory will automatically add ASP.NET Ajax endpoint to your service. Finally point your "path" attribute to this newly created "TradeService.svc".

You can test your service by visiting http://localhost.me/TradeService.svc

And Ajax support can be tested at http://localhost.me/TradeService.svc/jsdebug

Reference : http://berniecook.wordpress.com/2012/01/08/consuming-a-wcf-service-with-jquery-or-scriptmanager/

SourceCode : https://docs.google.com/open?id=0Bz2usIBCcor0NDQxZDc2ODYtNTUzMi00OTRlLTlhOGMtMGI4Y2RhNGIzYWNj

Shawinder Sekhon
  • 1,569
  • 12
  • 23