.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Web Service - Different Operation Contracts calling the same method

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :WCF
I would like to know how could I define two operation contracts (JSON, XML) which call to the same method; I have defined web and basic http bindings for all the Operation Contracts in the way that they could be called from HTTP requests (jQuery) and from Silverlight.

This first example works because the methods have different number of input parameters. But I need to add the attribute name to the Operation Contract.

        [WebInvoke(Method = "POST",
            UriTemplate = "1/json/getRegions",
            ResponseFormat = WebMessageFormat.Json)]
        RegionListOutput GetRegionList(int countryID, int other);

        [OperationContract(Name = "getRegionsXML")]
        [WebInvoke(Method = "POST",
            UriTemplate = "1/xml/getRegions",
            ResponseFormat = WebMessageFormat.Xml)]
        RegionListOutput GetRegionList(int countryID);


View Complete Post

More Related Resource Links

calling WCF service Method in HTTP GET by browser or ASP.NET ( like HttpWebRequest for example)

Can i call a WCF service Method using HTTP GET by browser or ASP.NET (without WCF Client)? it can be done with asmx web service.... but i can't find a way to call a WCF service Method with HTTP GET through the browser or C# ASP.NET Code... can i do that ?

Service Operation - Get proper data when browsing the service, but not when calling the service from

Hello, I recently implemented a service operation in an attempt to pass some filter parameters to a data service (a user guid and an organization, actually, for impersonation of a user on the service's call to the application). I successfully added the service operation to the data service, and I can browse the service and see the data filtered as I expected. However, when I call the service operation from the Silverlight client, I don't get any results, even though I should. Am I missing something? Code below if it's helpful. Thanks! Service Operation Definition: [WebGet] public IEnumerable<opportunity> filteredopps(string userid, string org) { /*Define the connection with the impersonated user*/ CrmConnection crmc = CrmConnection.Parse("Authentication Type=Passport; Server=https://" + org + ".crm.dynamics.com/" + org + "; User ID=myuser; Password=mypassword; Device ID=mydeviceid; Device Password=mydevicepassword"); crmc.ImpersonatedUser = new Guid(userid); var crmOnline = new DataContext(crmc); List<opportunity> uplist = new List<opportunity>(); crmOnline.UsingService(service => { var query = from o in crmOnline.opportunityopportunities select o; foreach (opportunity thisopp in query) { uplist.Add(thisopp);

Calling a Web Service Method Asynchronously does not work in Console Application

I have a web service that has a CreateReport method that generates a report based on the specified criteria. When I call this method Synchronously using a Windows Application or Console Application, the call works fine and the report is created. When I call this method ASynchronously (CreateReportASync) using Windows Application the report is created. When I call this method ASynchronously (CreateReportASync) using Console Application the web service does not even get the call.  I am using VS2005 and .Net Framework 2.0.  So the proxy is automatically created with the Async methods.  I am not really interested the result of the method call, so I do not add a Callback Delegate.  

SoapException when calling web service method.


Hi all,

I am stuck with this for a 2 days now. I have referenced 3rd party web service in my project. I am programmatically setting credentials to the service. Within debug it shows the dialogue box when calling web service method saying, Also within the debug it says,

Unable to automatically step into the server. Connecting to the server machine 'domain' failed. Invalid access to memory location.

And when I step out of the code it catches, System.Web.Services.Protocols.SoapException.

I did a Response.Write on all properties of this SoapException and got this string.

MESSAGE: Internal Error, CODE: http://schemas.xmlsoap.org/soap/envelope/:Server, DETAIL: System.Xml.XmlElement, NODE: , HELPLINK: , ROLE: , ACTOR: , INNEREXCEPTION: , IP: ::1

It returns Internal Error with no error code and I am stuck as what possibly I am doing wrong that is causing this exception. I am unable to check the resulting Xml generated behind the scene becuase it is not logged on the server web service is hosted on. Or if there is a way to fetch Xml when I call method on service, let me know. Thanks.

Please help me solving this horrific problem...

Calling a data-driven web service method asynchronously


I am trying to write a Windows Service which will call web service methods based on a run schedule.  I have setup a ‘schedule’ table which holds the name of the web service method and some scheduling details (e.g. run every day at 0200).  I am using VS 2005/vb.net.

My service creates a timer which runs every minute and when the timer is fired the schedule table is read and  any entries which are due to fire are actioned.  This could mean multiple methods being fired at the same time.  As some of the methods are overnight batch processes and may take some time, I don’t want processes to wait for others to finish before being actioned.  As the methods themselves write to the system log to report their success or failure the scheduling service does not care whether the job fails or not – it is simply doing a ‘fire and forget’ exercise.

What I need is some code which will fire a data-driven web service method asynchronously.

I have investigated two types of method call.  The first is a simple InvokeMethod:-

mywebservice.GetType().InvokeMember(ScheduleRow("WebMethod").TOString(),(Reflection.BindingFlags.InvokeMethod Or Reflection.BindingFlags.IgnoreReturn), Nothing, mywebservice, Nothing)

The second is an asynchronous call:-

Dim asyncCall as New AsyncCallB

Getting Error When Calling Wrokflow Service - The operation could not be performed because WorkflowI


The scenario .  ..

I have developed a Custom Activity(CA) which has a designer like SEQUENCE.

I created a Workflow Service (XAMLX) and placed my Custom Activity(CA) as the first activity. Then I placed a RECEIVE activity within this CA and provided all the necessary details.

Now if I run the workflow service and call the service operation it is throwing execption.

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

The operation could not be performed because WorkflowInstance 'a74eb5e2-72b4-4cb1-8a4d-daed6f431936' has completed.

Instead if I put the original SEQUENCE activity as first activity and then placed a RECEIVE activity it is working good. But I don't want to use SEQUENCE activity here . .. . I need my custom SEQUENCE like activity to be the first activity and make this as a place holder for other activities.

Please help to get out of these errors.


WCF Tip: Using Properties in Service Contracts

you'll notice all of the Service Contracts are implemented with interfaces containing only methods. For the longest time I thought that's all that was supported, until I thought about it a little more. In C# land, properties are simply wrappers around a get method and set method, so why wouldn't we be able to use properties in a service contract? Well the answer is we can.

A lengthy operation in an ASP.NET web service


I've built an ASP.NET web service with .NET 2.0 (an asmx file). I invoke a web service method using Ajax. The method takes a substantial amount of time to execute (5 minutes to 1 hour). I believe it's not a good idea to "hang" the web request for so long.
I'm wondering if the web service method could spawn an additional process which in turn would execute the lengthy operation and notify the web service once the operation is completed.
Are there any good practices regarding this kind of functionality?


Calling parameterized method from aspx file


Hi all,
I have following method
 public string GetYoutubeVideo (string code)
        return "asasdasfa"

CRUD Operation should be Part of BO or Service/Manager Classes?



I am developing an application which has a general structure similar to what Scott has described at http://nhibernateasp.codeplex.com

Thanks to Scott for developing such a nice architecture which can be used for most of the projects!

It uses Service Layer which contains service classes (like Product Service) which actually talk to the repository layer (ProductRepository) and these service classes are responsible for CRUD operations while the BO (Product) contains just the data and the validation methods.

As I have read, in OO design, you should design a class which contain both data and behavior, in which case, the BO (Product) should be responsible for doing its own CRUD and it should not be a responsibility of Service classes.

Which approach you think is better design and what could be the reasons?

Any help is this regard is appreiciated.




VS2005 calling VS2010 asmx service returns empty string


Anyone have any experience with this?

We are using VS 2005 for the front end, and vs 2010 for the web services part (asmx), not wcf yet.


Web service works just like the vs2005 when run locally, no problems.


Connecting to it from a test app returns an empty string. Connecting to a 2005 app doesn't!

Anyone run into this before or have a suggestion? Surely vs 2005 can connect to web services from a later version?






Cash Drawer - Method Open threw an exception - Windows Service

Hi All, I'm getting the following exception while calling Open method of Cash Drawer object. Method Open threw an exception.  Could not read the device name key's default value, or could not convert the Programmatic ID it holds into a valid Class ID. Code:   class Class1 { CashDrawer _uniCashDrawer1 = null; DeviceInfo cashDrawerDevice1 = null; PosExplorer posExplorer = new Microsoft.PointOfService.PosExplorer();   public void ClaimCashDrawer() { cashDrawerDevice1 = posExplorer.GetDevice("CashDrawer", "testDrawer"); if (cashDrawerDevice1 != null) { _uniCashDrawer1 = posExplorer.CreateInstance(cashDrawerDevice1) as CashDrawer; if (_uniCashDrawer1 != null) { _uniCashDrawer1.StatusUpdateEvent += new StatusUpdateEventHandler(UniCashDrawer1_StatusUpdateEvent); _uniCashDrawer1.Open(); _uniCashDrawer1.Claim(0); _uniCashDrawer1.DeviceEnabled = true; } } } }   Tha above code works fine if you put the code in WindowsApplication in all POS systems. The same is working if you put the code in Windows Service in all other POS systems. The same is not working if you put the code in Windows Service in Aures Galeo POS systems.  Thanks in advance. Ramakrishnan S

Calling an asp.net web service from jQuery

As I have post it in earlier post that jQuery is one of most popular JavaScript library in the world amongst web developers Lets take a example calling ASP.NET web service with jQuery . You will see at the end of the example that how easy it is to call a web service from the jQuery. Let's create a simple Hello World web service. Go to your project right click->Add -> New Item and select web service and add a web service like following.   Now modify the code of web service like following. [WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.ToolboxItem(false)]// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService]public class HelloWorld : System.Web.Services.WebService{ [WebMethod] public string PrintMessage() { return "Hello World..This is from webservice"; }} Here please make sure that [System.Web.Script.Services.ScriptService] is un commented because this attribute is responsible for allowing web service to be called by Client side scripts. Now to call this  web service from jquery we have to include jQuery Js like following. I am already having in my project so i don't need to include in project just need to add script tag like following. <script type="t

calling a web service on a remote server from an ASPX page

hi, I want to call a web service on a remote server. I've done "add web reference" in my project, and VS2005 has created the .discomap and .WSDL in the App_Web_Reference folder. When I try add the namespace representing the web server (the name I created when I added the web reference) by "using XXXXX;" the code does not compile because XXXXX is not defined. Have I missed any steps? thanks, -me

While calling Web service gets exception "The request failed with HTTP status 401: Unauthorized"

Hi All, I created a ASP.NET web service, which was hosted on default visual studioserver, and on excecution of webservice it run .exe file which in turn update xml file. Now i hosted this webservice on IIS 6.0 server, and when i run the service, itfails to execute the exe.When i run it on debug mode, i never get any exception.Code...public string HelloWorld()    {        Process myProcess = new Process();        try        {            myProcess.StartInfo.UseShellExecute = false;            // You can start any process,             myProcess.StartInfo.FileName = @"E:\Projects\some.exe";            myProcess.StartInfo.CreateNoWindow = true;            myProcess.Start();            myProcess.Close();            myProcess.Dispose();            return "Suceess";         }&n

calling a web service on a remote server from a ASPX page (web site project VS2005)

HI,I am maintaining a web site project in VS2005 and have to call a new web service on a remote server. I've done add web reference, and created the .wsdl and .discomap files in the app_webReference folder.  When I try to create a object representing the web service in the code ( wsnamespace.serviceName ws = new wsnamespce.serviceName(); ) the code wouldn't compile.The web site project is already calling other web services. When I right click on the type representing the web service and "go to definition" it takes me to a proxy class (derived from of course SoapHttpClientProtocol) in the metadata. I think this is what's missing for  the new web service i'm trying to call. Have I missed any steps?Thanks in advance.-me

Error calling WCF service that is returning list.".Debugging resource strings are unavailable ......

Ok.this is just making me frustrated... Here is step by step of what I am trying to do (& not able to) 1. I am calling WCF service hosted in a SharePoint 2010 site from a silverlight app in same domain (So no cross doman I guess). 2. I use Linq to Sharepoint for querying the DB. 3. I am having a list "machines" in Sharepoint 2010 that is having a lookup column from Other list called "part" 4. My WCF method GetAllMachines() works perfectly well when it skips the lookup column "partname" & returns List of type machineitem. 5. But problem occurs when I add machineitemobject.parts.partsname in my Linq to Sharepoint query . My service gives the error not found Async_ExceptionOccurred] Arguments: Debugging resource strings are unavailable." 6. Note that return type of my Method is List<machinesitem> 7. The point to note here is that I use SPMETAL tool to generate the LINQ class that maps the lists . So When I try to query the lookup column it tries to add List item of the type class & that is what causing the error. Is it because I am not using datacontract in my service (but it returns the strings & all private members of machines list e.g. name,title etc) Is it making the attribute Serialisable will solve the error ??? I am kind of lost in it ...Plss help!!   Thanks
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend