1

I've just started experimenting with C#/.NET and for my first project I'm creating a webservice.

I followed this very brief tutorial (mono-project.org), and can connect successfully via my browser after running xsp4 from the command-line.

My question - how do I import a .cs file containing a namespace + several class definitions from my main .asmx file? When I run xsp4, it does't take any command-line arguments unlike the mono-csc compiler in which you tell which files you want to compile into the final output.

When I try to reference a class (prefixed by its namespace) defined in one of these .cs files, it simply tells me that the namespace cannot be found.

Here's some simple code:

<%@ WebService Language="C#" Class="MathService.MathService" %>

using System;
using System.Web.Services;
using System.Collections.Generic;

using com.example;

namespace MathService
{
    [WebService (Namespace = "http://tempuri.org/NumberService")]
    public class MathService : WebService
    {
        [WebMethod]
        public int AddNumbers (int number1, int number2)
        {
            return number1 + number2;
        }

        [WebMethod]
        public int SubtractNumbers (int number1, int number2)
        {
            return number1 - number2;
        }

        [WebMethod]
        public com.example.Response GetBalance(com.example.Request request)
        {
            com.example.Response response = new com.example.Response();
            return response;
        }
    }
}
2
  • 1
    Did you see the part about "This page is likely outdated (last edited on 16 Nov 2007)"? You should be using WCF for new web service development. Dec 10, 2014 at 2:21
  • I did notice that - however that was the newest version of that page available. Thanks for the WCF tip. Dec 10, 2014 at 3:26

1 Answer 1

2

You mean, the @import? Should be at the very first lines of your page:

<%@ Import namespace="MyAssembly.MyUnit" %>

http://msdn.microsoft.com/en-us/library/eb44kack(v=vs.85).aspx

2
  • 1
    It is not different, it is the same. But you are using the .asmx extension. This means you are writing a page-script like code. You could implement your WS in a code behind file, then it would be a .asmx.cs and then you would use a using statement.
    – rodrigogq
    Dec 10, 2014 at 3:46
  • "using" is just fine, since it's in the body of the code. Dec 10, 2014 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.