59

I have a WSDL file and I am trying to create a web service that conforms to the WSDL.

I've created clients using WSDL files that consume an existing service, but I've never created a web service that needed to follow a specific WSDL.

I've gone as far as using:

wsdl.exe mywsdl.wsdl /l:VB /serverInterface

Now I've got a .vb file generated from that WSDL. However I am not sure what I'm supposed to do with this VB file. It looks like it's got a public interface in there but no class that implements the interface. It also has a bunch of partial classes for the types in the WSDL.

I was expecting there to be some sort of stub where I put in the code to complete the service calls. I've only created simple web services before and none of them used public interfaces so I'm unfamiliar with what is going on here.

At this point I'm not sure how I use the generated .vb file and make it work with an .asmx file and what additional coding is needed to complete the interface.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
dtc
  • 10,136
  • 16
  • 78
  • 104
  • @webdtc: thanks for this question, it was EXACTLY my question today, and answered it perfectly. Thanks again! – p.campbell May 19 '09 at 16:07
  • 1
    thanks, +1. The wsdl.exe syntax refresher and subsequent answer saved me a lot of time. – b w May 25 '10 at 20:45

2 Answers2

35

If you already created interfaces you need to implement those interfaces.
Just create a new web service and add the interface that you generated so that it inherits from that interface. Visual Studio can automatically generate stubs for every method in interface. Mark them with the WebMethod attribute and put some code in that will return some test data/results.

If you have this interface (with some more attributes that were automatically generated):


public interface IRealWebService
{
    string GetName();

}

You should make a new service:


public class WebTestService : System.Web.Services.WebService, IRealWebService
{

    #region IRealWebService Members

    [WebMethod]
    public string GetName()
    {
        return "It Works !!!!";
    }
    #endregion
}
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
Robert Vuković
  • 4,677
  • 6
  • 31
  • 47
  • Thank you. I think this is it. I understand what is going on now! Maybe I should have did it in C# first. I have to do it in VB.net and I'm not that familiar with VB.net yet. But I understand your example perfectly and am able to do it in C#. – dtc Feb 15 '09 at 03:44
  • This got me part of the way there. In .Net 4.0, I had to also add [SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)] to my class and then it worked. This site describes it a bit more: http://gsmblog.com/post/Solving-problems-with-the-MS-header-SOAPAction.aspx. I don't know if it helped, but I also removed all other attributes from my webservice, like WebService, WebServiceBinding, System.ComponentModel.ToolboxItem, and System.Web.Script.Services.ScriptService. – Clay Lenhart Feb 11 '11 at 11:16
  • Has anyone come across a wsdl that includes a method that has an object request as a parameter and a response object as the return type? – Ben Sewards Oct 16 '12 at 17:12
  • When accession the wsdl there is no details Knowing that the service is working fine any idea ? – Hussein Zawawi Jul 11 '13 at 08:29
4

All you need to do is create a class that inherits from the interface that WSDL.EXE has generated, and then implement the methods from the interface.

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