WCF / ASMX :: Web Service To Inherit From A Custom Base Class That Inherits System.Web.Services.WebMethod Inste...

Oct 18, 2010

Recently, I tried to get my Web Service class to inherit from a custom base class that inherits from System.Web.Services.WebMethod instead of the System.Web.Services.WebMethod directly.

However, I've been getting Error 500.

Public Class Service1
Inherits BaseClass
<System.Web.Services.WebMethod()> _
Public Function GetSessionID() As String
GetSessionID = Me.Session.SessionID
End Function
End Class

public class BaseClass
Inherits System.Web.Services.WebService
public property Property1 as string
public property Property2 as string

End Class

View 6 Replies


Similar Messages:

How To Create A Custom Class That Inherits From System

Apr 22, 2010

I wanted to create a custom class that inherits from System.Exception and adds a few properties and methods specific to the project.

The issue I'm seeing is that a standard try/catch block catches generic Exception class and the compiler thinks that converting that to my custom class is OK. However, at runtime if the actual error is something else like a a System.Net.WebException for instance, then at runtime it will not convert to my custom class. Then my own error catch throws an InvalidCastException.

Obviously the one thing I don't want to happen is to have my error logging methods throw errors on their own...

So, how can I convert ANY exception to something that my custom class can use?

Here's a code example:

Csharp Code:

[code]....

Now, this code builds just fine... VS2008 and VS2010 have no issue with converting an "Exception" to "MyErrorClass", but at runtime it certainly doesn't like converting a "WebException" to "MyErrorClass"...

View 9 Replies

WCF / ASMX :: Web Service - WebMethod Accepting Custom Object?

May 11, 2010

I have a custom class declared as follows (in vb.net)

<Serializable()> _
Public Class NumInfo
Public n As String
Public f As Integer
Public fc As char()
Public t As Integer
Public tc As char()
Private validFlag As Boolean = True
Public Sub New()
End Sub

I also have public properties(read/write) for all the public variables

End Class
In my service.asmx codebehind class I have a webmethod as follows:
<WebMethod> _
<XmlInclude(GetType(NumInfo))>
Public Function ConvertTo(ByVal info As NumInfo) As String
Return mbc(info)
'mbc is another function defined in my service.asmx "service" class
End Function

The problem is that when I start debugging it to test it, the page that I get does not contain any fields where I could input the values for the public fields of numInfo. How do I initialise the class? There is no "Invoke" button either. All I see are soap details as below:

ConvertTo
Test
The test form is only available for methods with primitive types as parameters. SOAP 1.1 The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /BaseConverter/BaseCon.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://RohitServices.in/ConvertTo"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ConvertTo xmlns="http://RohitServices.in/">
<info>
<n>string</n>
<f>int</f>
<fc>
<char>char</char>
<char>char</char>
</fc>

What am I doing wrong? For the record I tried replacing char() with string to see if it was the array causing problems but that didn't help either. I'm fairly new to web services. I tried replacing the custom object parameter with a primitive parameter just to check how things worked and it rendered a page with an input field and invoke button. I just can't seem to get it working with custom object.

View 2 Replies

Web Services - Can A Webservice Class Inherit Page Class?

Jan 6, 2011

i have an application consisting of two asp.net projects. And i have have a BasePage which inherits System.Web.UI.Page and have the class some core logic which i require in all of my pages(Implemented in BasePage.cs). So all my pages inherit this BasePage.cs . Now can an Webservice inherit the same class apart from the normal webservice class System.Web.Services.WebService

View 4 Replies

How Does The Child User Control Inherit The Markup From The Base Class

May 25, 2010

I have a user control (uc1) which inherits from uc2. uc2 has a user control (uc3) declared in the markup. I am trying to access uc3 from uc1 but I get NullReferenceException. I thought due to inheritance uc3 would instantiate but looks like I am missing a step.

Clarification:

How does the child user control inherit the markup from the base class? The server controls in the base user control are null in the code behind of the base user control. Why?

View 4 Replies

Web Forms :: Master Pages - All My Pages Inherit From The Base Page Class

Jun 21, 2010

Currently I'm doing common functionality required throughout my site inside of my masterpage. What I want to do is move this functionality to a BaseClass so All my pages inherit from the Base Class. However, I'm not sure how to set this up interms of c# code with regards to Using a Base Class and then having a masterpage applied to my aspx pages that i create.

View 5 Replies

Mvc - Can Set A Custom Class As The Default Base Class For Controllers In MVC3

Feb 15, 2011

I'd like to inherit all my controllers from a custom base class that I write myself. I can change the line every time I add a new controller, but it would be nicer if I could somewhere specify the default value that gets set there. That way I wouldn't need to worry about forgetting this, and other people who get added to the project later on would have an easier time.

View 3 Replies

WCF / ASMX :: Calling A Class Method On Webmethod?

Dec 10, 2010

i wrote a webmethod on webservice. it will do adding product to shoppingbasket. But it doesn't work. i used a class and its method in this webservice method. error is about it. my code are below:

[Code]....
[Code]....

View 4 Replies

C# - Inheriting From A System.Web.UI.UserControl Base Class?

Feb 28, 2011

First off, I am wondering if this is possible. I read slight grumblings around the internet about this, but I was not entirely sure.

My scenario: I have a base chart class which has some methods which all charts should have.

public partial class BaseChart : System.Web.UI.UserControl
{
public BaseChart()
{
}
public void ToggleLegend()
{
Chart1.Legends[0].Enabled = !Chart1.Legends[0].Enabled;
}
}

There is also some mark-up for this BaseChart -- setting background colors, etc. All charts which inherit BaseChart should use this starting mark-up and be able to build upon it.

I would then like to do this:

public partial class HistoricalLineChart : BaseChart
{
public HistoricalLineChart()
: base()
{

public HistoricalLineChart(int reportID)
: base()
{
Chart1.Titles[0].Text = "Hello World";
}
}

where HistoricalLineChart is a web user control with no mark-up e.g. "HistoricalLineChart.ascx"

The problem is that Chart1 is undefined when in HistoricalLineChart's scope. Is there something that I am missing here?

View 3 Replies

WCF / ASMX :: Access Web Service Webmethod In Javascript?

Apr 29, 2010

How to Access Webservice Webmethod in Javascript

View 4 Replies

WCF / ASMX :: Obtain URL Inside A WebMethod In .NET Web Service?

Sep 24, 2010

<WebMethod(Description:="Tests the authentication of a given set of user credentials..")> _

View 2 Replies

Using Both Post And GetAjax Calls For The Same WebMethod In ASMX Web Service

Jan 20, 2010

I can't seem to call a web service method from Ajax with both POST and GET.

Initially only the POST would work and GET would causes this error:


{"Message":"An attempt was made to call the method u0027getDatau0027 using a GET request, which is not allowed.","StackTrace":" at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext
context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

I fixed that by adding this attribute: [ScriptMethod(UseHttpGet=true)] but now GET causes this error:

[code]....

So is it true that you can only use either POST or GET and not both from Ajax?

View 3 Replies

Add A Custom Base Class For Web Forms?

Jan 12, 2010

I want to add a custom base class for all of my web forms. I created a "App_code" folder in my asp.net web project and add a simple base page class like this:

namespace MySite.Web
{
// base page for all the pages that need localization
public class LocalizationPage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
base.InitializeCulture();
}
}
}

And then I try to let asp.net web form to inherit from this base page. I have something like this:

using MySite.Web;

namespace MySite.Public
{
public partial class RegisterPage : LocalizationPage
{
}
}

Now I run into problem where Visual Studio doesn't recognize the LocalizationPage class I created. On the above code snippet, LocalizationPage is not highlighted as a class. And when I try to compile, I got the following error message:

Error 1 The type or namespace name 'LocalizationPage' could not be found (are you missing a using directive or an assembly reference?)

View 1 Replies

Passing Custom Object As Parameter To A Webmethod Of Web Service?

May 11, 2010

I have a custom class declared as follows (in vb.net)

<Serializable()> _ Public
Class NumInfo Public n As String
Public f As Integer Public fc As
char() Public t As Integer

[Code]....

What am I doing wrong? For the record I tried replacing char() with string to see if it was the array causing problems but that didn't help either. I'm fairly new to web services. I tried replacing the custom object parameter with a primitive parameter just to check how things worked and it rendered a page with an input field and invoke button.

View 1 Replies

MVC Generic Base View Class / Error Parsing Attribute 'something': Type 'System.Web.Mvc.ViewPage'

Feb 5, 2010

I can have a base class for views in an MVC project like this:

public class BaseViewPage : System.Web.Mvc.ViewPage
{
public string Something { get; set; }
}

And then in the ASPX I can do this:

<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage" %>

This works fine; the problem is when I try to do the same with the generic version:

public class BaseViewPage<TModel> : System.Web.Mvc.ViewPage<TModel> where TModel : class
{
public string Something { get; set; }
}

When I try to use this from the ASPX, like this:

<%@ Page Something="foo" Language="C#" Inherits="MyNamespace.BaseViewPage<SomeClass>" %>

I get the error message:

Error parsing attribute 'something': Type 'System.Web.Mvc.ViewPage' does not have a public property named 'something'.

Notice how it tries to use System.Web.Mvc.ViewPage rather than my BaseViewPage class. To make it more interesting, if I remove the "Something" attribute from the Page directive and put some code in the generic version of BaseViewPage (OnInit for example) the class is actually called / used / instantiated.

So, am I doing something wrong or is this a limitation.

View 1 Replies

MVC :: Access HTTPContext And Session From Custom Base Controller Class?

Jan 13, 2010

I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.

My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.

Am I doing something wrong or need missing something?

My custom base class definition:

public class ApplicationControllerBase : Controller

controllers classes definition:

public class HomeController : ApplicationControllerBase

using ASP.NET MVC 1, .NET 3.5.

UPDATE:

It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.

My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.

View 3 Replies

AJAX :: Is It Possible To Call A Custom Method Or Class Before Accessing Webmethod From PageMethods

Jan 19, 2010

is it possible to call a custom method or class before accessing webmethod from pageMethods ?

View 2 Replies

How To Force Web Service Base Class Method Run Before Web Service Method Start

Aug 6, 2010

My web services have base web service method called IsGood()I want to make sure every methods in my web service call IsGood() in base web service automatically without add code in each web service method, can I do that?

View 2 Replies

WCF / ASMX :: Only Web Services With A [ScriptService] Attribute On The Class Definition Can Be Called From Scr...

Nov 4, 2010

I have created a web service. When I check the service directly from it's web page it works correctly. Here's what the code looks like:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Configuration;
using System.Runtime.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using Microsoft.SharePoint;
using System.Collections;
namespace MDA.WebParts.SPRolodex_Web_Service
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class SPRolodex_Web_Service : System.Web.Services.WebService
{
public SPRolodex_Web_Service()
{
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool ListExists(string personalUrl, string listName)
{
try
{
SPSite mySite = new SPSite(personalUrl);
SPWeb web = mySite.OpenWeb();
SPList list = web.Lists[listName];
return true;
}
catch (ArgumentException)
{
return false;
}
}
}
}

However, when I call the method using ServiceProxy.js (a jQuery based library) I get this error

"Only Web services with a [ScriptService] attribute on the class definition can be called from script."

As you can see the class has the ScriptService attribute and the methods have the ServiceMethod attribute.

View 1 Replies

C# - Why Is System.Data.Services.MimeTypeAttribute Now Only A Class Level Attribute

Apr 7, 2010

I'm getting started with Astoria/ADO.NET Data Services/WCF Data Services. Looking through a lot of the code samples out there, it appears that the MimeType attribute used to be a method level attribute. After installing the latest update, it is now a class level attribute.

If I have more than one Service Operation that I want to return as a certain MimeType, then it appears now that I have to create a new service for each operation. Is this correct?

Most examples are like this:

[WebGet]
[SingleResult]
[MimeType("application/pdf")]
public IQueryable<byte[]> FooPDF()
{
var result = from p in this.CurrentDataSource.MyPDFs
where p.FooID == 2
select p;
return result.Take(1).Select(p => p.PDF);
}

I get "Attribute 'MimeType' is not valid on this declaration type. It is only valid on 'class' declarations." when I compile, because now I can't do this.

Now, I have to do this:

[MimeType("FooPDF", "application/pdf")]
public class FooService : DataService<FooDBEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetServiceOperationAccessRule("FooPDF", ServiceOperationRights.All);
}
[WebGet]
[SingleResult]
public IQueryable<byte[]> FooPDF()
{
var result = from p in this.CurrentDataSource.MyPDFs
where p.FooID == 2
select p;
return result.Take(1).Select(p => p.PDF);
}
}

What's worse is that I can't add duplicate MimeType attributes to my class.

View 1 Replies

Does Anyone Know A Good Practice To Use When Developing For The System.directory Services Class

Jan 31, 2011

I'm trying to create a data access later using System.DirectoryServices. I'd like to use the MVC 2 framework and have all my views be mostly strongly-typed. Does anyone know any good way to this?

For example I started creating a Group Entity:

public class Group
{
public string DistinguishedName { get; set; }
public string GroupName { get; set; }
}

And an abstract interface:

public interface IGroupRepository
{
List<Group> Groups { get; }
}

I am confused about developing the GroupRepository using the system.directory services. Connecting to a SQL database is easy there are examples everywhere but I have no been able to find any using the System.directory sevices in conjunction with a class using MVC. Has anyone tried to do something like this?

View 1 Replies

WCF / ASMX :: Create Web Service From WSDL File (top Down Approch For Web Services Development)

Jul 7, 2010

I have a WSDL, and I need to write this web service. (I am not the client, I am the provider of this service) Is there any tool and/or best approch to create this Web Service?

View 1 Replies

WCF / ASMX :: Custom WSDL File Generation For Classic Web Services (not WCF)

Mar 5, 2010

I'm about a custom WSDL File Generation for a Classic ASP.NET XML Web Service.

The issue is I didn't find out how to specify mandatory parameters in my WSDL, since ASP.NET Web Services are generated on ?WSDL location, I thought I would do that from Web Method Annotations, but I found no issue.

Also I have been on a pose where the developer could hide WSDL Generation by specifying a custom WSDL Binding. But in my case I need to let other system access ?WSDL location with a Customized WSDL.

View 1 Replies

C# - Is It Possible For A Derived Controls To Inherit His Base Control Skin

Feb 2, 2011

Is it possible for a derived controls to inherit his base control skin.

Say I am deriving a control from TextBox, is it possible for the derived control to inherit the skin settings for Textbox or do they need to be defined again?

I am applying the default skins to all controls through the styleSheetTheme Page property I am using the Devexpress asp.net controls if that makes any difference.

View 2 Replies

Custom Server Controls :: Register Tagprefix For A Custom Control That Inherits Treeview?

Jun 15, 2010

I have an ASP.net web application project written in VB. Am trying to test a cobbed-together "MyTreeview" control put together from C# code that's been converted.

I think this will come "close" to what I'm trying to do - just get a treenode to have a CSS tag and render properly.

I have an App_LocalResources directory and a file called CustomTreeNode.vb. Inside that file is the following code:

[Code]....

[Code]....

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved