Hello:
I have here a problem where I am using web services.
From this example you can see that webservices is very
tolerant of extra fields or missing fields.
One issue though is that if you run one of the webservices and then
update the other project's web reference it generates partial class code for
your remote object in the namespace of the webservice. This is a problem.
For instance:
If you run the solution Version1 and then open
the solution
Version2 and update the Web Reference in the
project (you have to show hidden files) you get a file called Reference.cs.
In Reference.cs the system generates a wrapper for the
class Foo
///
<remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml","2.0.50727.1378")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial
class Foo {...}
The problem is that when it does this it will return this
object as when you call HelloWorld.
static void
Main(string[] args)
{
ConsoleApplication1.localhost.Service1 s1 = new Service1();
MyLibrary.Foo f1 = new MyLibrary.Foo();
f1.Prop1 = "New";
MyLibrary.Foo f2 = (MyLibrary.Foo)s1.HelloWorld( f1);
System.Console.WriteLine("F1.Prop1=" + f2.Prop1);
}
Which is not what you want. The intended object is MyLibrary.Foo not
ConsoleApplication1.localhost.Foo. Please figure out how prevent VS from creating the wrapper or any other solution.
Below are the project codes:
"Version1" Solution:Webservices:using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Xml;
using System.Xml.Serialization;
using MyLibrary.Lib;
namespace Version1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://localhost/")]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
[XmlInclude(typeof(Foo))]
public MyLibrary.Lib.FooHelloWorld(MyLibrary.Lib.Foo foo1)
{
foo1 = "Updated";
return foo1;
}
}
}
"MyLibrary.cs"
using System;
using System.Data;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
namespace MyLibrary
{
public class Foo
{
private string m_prop1 = null;
public string Prop1
{
get { return m_prop1; }
set { m_prop1 = value; }
}
private string m_prop2 = null;
public string Prop2
{
get { return m_prop2; }
set { m_prop2 = value; }
}
public Foo()
{
m_prop1 = "abc";
m_prop2 = "cde";
}
}
}
Console application: "Program.cs"
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using MyLibrary.Lib;
namespace ConsoleApplication1
{
static void
Main(string[] args)
{
ConsoleApplication1.localhost.Service1 s1 = new Service1();
MyLibrary.Foo f1 = new MyLibrary.Foo();
f1.Prop1 = "New";
MyLibrary.Foo f2 = (MyLibrary.Foo)s1.HelloWorld( f1);
System.Console.WriteLine("F1.Prop1=" + f2.Prop1);
}
}
*** NOte *** localhost is the name of the web services when i add reference.
If you can provide solution in this Version1 solution it will work also on Version2 solution.
Hope anyone can save me from hell... Thanks