views:

581

answers:

3

Hi.

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.

A: 

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

pb
A: 

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
A: 

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.

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