[Mono-aspnet-list] creating new web service from wsdl

Devin Venable venable.devin at gmail.com
Thu Sep 2 13:41:04 EDT 2010


I believe I've answered my own question, so for the record, it seems you
need to also redeclare the [WebMethod] declaration in braces.  (What do you
call these things?)  Here's a complete example that works. (Imagine that
MathServiceBase.cs was generated by running wsdl2 from existing interface
file.)

MathServiceBase.cs:

using System;
using System.Web;
using System.Web.Services;

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

[WebMethod]
public abstract int SubtractNumbers (int number1, int number2);
}
}

Now you have to inherit, add override to the methods, and copy the [ ]
blocks from the generated file.

MathService.asmx:

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

using System;
using System.Web.Services;

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

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


2010/9/2 Devin Venable <venable.devin at gmail.com>

> And with NEW I get this error:
>
> TestService.asmx.cs(58,58): Error CS0533:
> `blah.blah.EnrollTransmitter(blah.TransmitterEnrollmentRequest)' hides
> inherited abstract member
> `blah.blahGenerated.EnrollTransmitter(blah.WidgetEnrollmentRequest)'
> (CS0533) (TestSOAP2)
>
>
>
> 2010/9/2 Devin Venable <venable.devin at gmail.com>
>
>> When I don't inherit, I get this compile warning:
>>
>> TestService.asmx.cs(54,54): Warning CS0114:
>> `MyService.MyService.EnrollTransmitter(GTPServices.WidgetEnrollmentRequest)'
>> hides inherited member
>> `MyService.MyServiceGenerated.EnrollTransmitter(TestService.WidgetEnrollmentRequest)'.
>> To make the current member override that implementation, add the override
>> keyword. Otherwise add the new keyword (CS0114) (TestSOAP2)
>>
>> Should I use the new keyword?
>>
>>
>> 2010/9/2 Alberto León <leontiscar at gmail.com>
>>
>>> Y do not need to override WidgetEnrollmentResponse.
>>>
>>>
>>> 2010/9/2 Devin Venable <venable.devin at gmail.com>
>>>
>>>> Simple inheritance didn't seem to work, at least not using my pattern.
>>>>  Here is a fragment of the code (variable names changed to protect the
>>>> innocent):
>>>>
>>>> In TestService.asmx:
>>>>
>>>> <%@ WebService Language="C#" Class="MyService.MyService" %>
>>>>
>>>> In MyServiceGenerated.cs:
>>>>
>>>> namespace MyService
>>>> {
>>>>
>>>> /// <remarks/>
>>>> [System.Web.Services.WebServiceAttribute(Namespace="http://tempuri.org/
>>>> ")]
>>>> [System.Web.Services.WebServiceBinding(Name="BasicHttpBinding_IMyServices",
>>>> Namespace="http://tempuri.org/")]
>>>> public abstract partial class MyServiceGenerated :
>>>> System.Web.Services.WebService {
>>>>
>>>>     [System.Web.Services.WebMethodAttribute()]
>>>>     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("
>>>> http://tempuri.org/IMyServices/EnrollTransmitter", RequestNamespace="
>>>> http://tempuri.org/", ResponseNamespace="http://tempuri.org/",
>>>> ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped,
>>>> Use=System.Web.Services.Description.SoapBindingUse.Literal)]
>>>>      [return:
>>>> System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
>>>>     public abstract WidgetEnrollmentResponse
>>>> EnrollTransmitter([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
>>>> WidgetEnrollmentRequest request);
>>>>     ...
>>>>
>>>> In TestService.asmx.cs:
>>>>
>>>> namespace MyService
>>>> {
>>>>  public class MyService : MyServiceGenerated
>>>>  {
>>>>
>>>> public override WidgetEnrollmentResponse
>>>> EnrollTransmitter(WidgetEnrollmentRequest request)
>>>>  {
>>>>                         // TODO implement
>>>> return null;
>>>> }
>>>>
>>>>
>>>> Okay, so now when I deploy this, the web page shows up and there are no
>>>> visible service methods.  What am I doing wrong, or better yet, what is the
>>>> best practice for what I'm trying to do?
>>>>
>>>> And thanks for the help!
>>>>
>>>> 2010/9/2 Alberto León <leontiscar at gmail.com>
>>>>
>>>> You need inherit MyServices in other class.
>>>>> An abtract class can't be instantiated, created, and can't store data.
>>>>> Allways need to be inherited.
>>>>>
>>>>>
>>>>>
>>>>> 2010/9/2 Devin Venable <venable.devin at gmail.com>
>>>>>
>>>>>>  Background:  Linux developer new to .NET.  In the past I've
>>>>>> successfully deployed simple web services by creating asmx files and running
>>>>>> them under Apache via XSP.
>>>>>> Need: Create web service implementation from WSDL defined by 3rd party
>>>>>>
>>>>>> This is what I've tried so far...
>>>>>>
>>>>>> 1. Used wsdl2 to generate server stubs.
>>>>>>
>>>>>> wsdl2 -server MyServices.wsdl
>>>>>> Web Services Description Language Utility
>>>>>> Mono Framework v2.0.50727.1433
>>>>>>
>>>>>> There where some warnings while generating the code:
>>>>>>
>>>>>>   MyServices.wsdl
>>>>>>     - This web reference does not conform to WS-I Basic Profile v1.1
>>>>>>         R2718: A wsdl:binding in a DESCRIPTION MUST have the same set
>>>>>> of
>>>>>>         wsdl:operations as the wsdl:portType to which it refers.
>>>>>>           * Binding 'BasicHttpBinding_IMyServices', in Service
>>>>>> Description
>>>>>>             'http://tempuri.org/'
>>>>>>
>>>>>>
>>>>>> (should this warning make me nervous?)
>>>>>>
>>>>>> 2. Renamed resulting cs file to MyServices.asmx
>>>>>> 3. Added header to file:
>>>>>>
>>>>>> <%@ WebService Language="c#" Codebehind="MyServices.asmx.cs"
>>>>>> Class="MyServices" %>
>>>>>>
>>>>>> This KINDA worked.  I can load up and view the page in my browser:
>>>>>>
>>>>>> http://localhost/MyServices.asmx
>>>>>>
>>>>>> But when I try to invoke a method on the service from the web forms
>>>>>> that display, I get a message like:
>>>>>>
>>>>>> *500 - Internal Server Error*
>>>>>>
>>>>>> System.MissingMethodException: Cannot create an abstract class 'MyServices'.
>>>>>>   at System.Activator.CheckAbstractType (System.Type type) [0x00000]
>>>>>>
>>>>>>   at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000]
>>>>>>   at System.Activator.CreateInstance (System.Type type) [0x00000]
>>>>>>
>>>>>>   at System.Web.Services.Protocols.WebServiceHandler.CreateServerInstance () [0x00000]
>>>>>>
>>>>>>   at System.Web.Services.Protocols.HttpSimpleWebServiceHandler.Invoke (System.Web.Services.Protocols.LogicalMethodInfo method, System.Object[] parameters) [0x00000]
>>>>>>
>>>>>>   at System.Web.Services.Protocols.HttpSimpleWebServiceHandler.ProcessRequest (System.Web.HttpContext context) [0x00000]
>>>>>>
>>>>>>
>>>>>> Though I'm not a .NET developer, I'm a developer and can see why
>>>>>> trying to create an instance of an abstract class would be an issue.  What
>>>>>> I'm not clear on is what is the best
>>>>>> pattern to implement the concrete methods.   I've tried implementing a
>>>>>> concrete class with all of the methods in the asmx and made the class
>>>>>> inherit from the class generated by
>>>>>> wsdl2, but when I run the application, the methods disappear.  I'm
>>>>>> guessing I need to copy all of the blocks that look like this into the
>>>>>> concrete class:
>>>>>>
>>>>>>  [System.Web.Services.WebMethodAttribute()]
>>>>>>     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("
>>>>>> http://tempuri.org/IGTPServices/EnrollTransmitter",
>>>>>> RequestNamespace="http://tempuri.org/", ResponseNamespace="
>>>>>> http://tempuri.org/",
>>>>>> ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped,
>>>>>> Use=System.Web.Services.Description.SoapBindingUse.Literal)]
>>>>>>     [return:
>>>>>> System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
>>>>>>
>>>>>> If anyone can point me to a short tutorial for creating a web service
>>>>>> in Mono using an existing WSDL, or give me tips herre, I would appreciate
>>>>>> it.
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Mono-aspnet-list mailing list
>>>>>> Mono-aspnet-list at lists.ximian.com
>>>>>> http://lists.ximian.com/mailman/listinfo/mono-aspnet-list
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Mono-aspnet-list mailing list
>>>> Mono-aspnet-list at lists.ximian.com
>>>> http://lists.ximian.com/mailman/listinfo/mono-aspnet-list
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20100902/d923c5b8/attachment.html 


More information about the Mono-aspnet-list mailing list