views:

144

answers:

3

I'm creating a custom class to abstract out some of the repeated SOAP header work. I want to reference a Web Service Reference I just created in my custom class so I can create an instance of it. How do I reference it?

Notice I said I am trying to reference a Web Service "reference" (right click in VS and I added a "Web Service Reference" not a "Web Service"). So I'm trying to create an instance of that Proxy class that was created in MyCustomClass.cs

A: 

Once you have the reference created you need to add an import(vb) or using(c#) statement in the code file you want to use it. After that you simply need to instantiate an instance of the web service class.

// add the service reference
using ServiceReference1;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //create the instance of the web sevice of the class
        SomeWebService sweb = new SomeWebService();
        //call the web services HelloWorld Method
        sweb.HelloWorld();
    }
}

Hopefully this was what you were asking for

cptScarlet
I tried that before posting this actually. I tried a using statement but it still did not know of it.
CoffeeAddict
did the using statement even pick it up?
cptScarlet
thing is, we're about to convert this Web Site Project to WAP. For now though it's a Web Site Project so not sure why the using is not picking it up. I'm adding using [name of the web service reference that shows up under App_WebReferences] and still it's not working
CoffeeAddict
Any way you could post a code snippet of how you are trying to do this?
cptScarlet
A: 

This is more Web Site weirdness. I recommend that web sites be used only for pages, images, css, js, etc, Anything else should be done in a separate project, and the web site can reference the other project.

I avoid web sites like the plague, so I've never had to make this work, but consider that web sites don't build. Instead, various things are built on the fly, when the site is used. There will be no Reference.cs file in a web site.

John Saunders
A: 

In more recent versions of Visual Studio the using statement for these web service references also has had to include the project name.

Using cptScarlet's original code example, change the first line to look like this:

// add the service reference
using MyProject.ServiceReference1;

When you type in your project name, the class and/or namespace of the objects created in the web reference should show up in the intellisense.

kdmurray
@kdmurray: since he's using a Web Site project, i don't think he has a "MyProject" namespace.
John Saunders