Search code examples
asp.netwcfvisual-studio-2013iis-7wcf-binding

When adding Web Reference for WCF to ASP.NET 2.0 there are two additional parameters added


I have developed a WCF in ASP.NET 4.5 with a couple of simple methods. One such method has a return type of bool (written in c#). When I add this service to my ASP.NET 4.5 web application as a Service Reference, it works as expected in the code behind. It also works the same way in a .NET 4.5 C# Console application. Below is the code in the Implementation file for this method:

public bool AddADUser(string a, string b)
{
    bool done = false;
    return done;
}

When I call it from my programs, it looks like this:

static void Main(string[] args)
{
    var proxy = new ServiceReference1.ADServiceClient();
    proxy.Open();

    try
    {
        Console.WriteLine(proxy.HelloWorld());
        bool success = proxy.AddADUser("testA", "testB");
        Console.WriteLine(success.ToString());
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.WriteLine(ex.InnerException);
    }
    finally
    {
        proxy.Close();
    }
}

This is how it works in my ASP.NET 4.5 / C# app, and my C# .NET 4.5 Console App.

When I add this as a "Web Reference" to an existing ASP.NET 2.0 / VB.NET app, it does something different. The command to call the AddADUser() function is all of a sudden requiring 4 parameters:

AddADUser(a As String, b As String, ByRef AddADUserResult As Boolean, ByRef AddADUserResultSpecified As Boolean)

Why are these parameters being added -- is this something with VB.NET not allowing this to actually return a boolean, or a web reference not being able to return a boolean, or a problem with this being ASP.NET 2.0 ?

Or do I need to make a custom DataContract? I have that part left out of my Interface, just relying on defaults. Do I need to specify XmlSerializer somewhere also to be able to use this? It appears to actually do what it is supposed to, and I just can't figure out why there are two booleans and which one is the one I want.


Solution

  • This page gives a long explanation about it and a weird workaround that I didn't feel like doing:

    http://www.codeproject.com/Articles/323097/WCF-ASMX-Interoperability-Removing-the-Annoying-xx

    What I wound up doing was adding [OperationContract, XmlSerializerFormat(Style = OperationFormatStyle.Rpc)] to my methods and I also added [ServiceContract,XmlSerializerFormat] to my interface attribute and now they act like I would expect.

    Reference: http://www.wenda.io/questions/1191041/result-and-resultspecified-parameters-in-wcf-service.html