Web Service Partial Class

I just converted an application that communicates with the database via web services to VS2005. The conversion worked fine but I could not get the application to communicate with the web services. I kept getting a web method error. So, I decided to convert the web services to VS2005 as well. The conversion of the web services went well also. However, when I generate the proxy class through WSDL.exe, and add the proxy class to my application, it will not compile. The proxy class generated by the WSDL.EXE utility for VS2005 creates a Public Partial Class and the compiler doesn't like it. It throws an error for each of the three Public Partial Classes generated by the WSDL.EXE utility that states: Expected class, delegate, enum, interface, or struct.

What am I doing wrong I'm following the exact same process that worked flawlessly in VS2003.



Answer this question

Web Service Partial Class

  • tta

    Yes, that worked! Thanks.

    I don't know if I've implemented the web services in the most efficient manner but it works. In VS2003, I simply generated a proxy class through the WSDL.exe utility. I then added the proxy class to my mobile application. Once the proxy class was added, I would add a constructor to the class, like so:

    public class Login (string URL) {Url = URL;}

    I also have a config file that gets added to the mobile device during installation that defines the URL location. The user can change the URL in the config file through the application, if necessary. The application uses the URL in the config file to communicate to the web service.

    Since the VS2005 proxy class generated by the WSDL.exe is not compatible with the .NET Compact Framework 2.0, I followed your suggestion and generated a proxy class within the mobile application in VS2005. I then copied the class from the web reference into my existing class, added my constructor, and then deleted the web reference and it works just as before.

    Do you see any issues with this design Is there a better way to manage the process I haven't been able to figure out another way to create an application that communicates with a web service that's not hard coded. I have the application at three different customer locations and would like to add additional customers. So, the ability to define the URL during installation is a big deal for me.

    Any suggestions would be appreciated!


  • General Fault

    Hi,

    I copied and pasted this class into VS2005 here and it compiled fine. Are you sure you're compiling with version 2.0 of the .NET framework


  • lcj

    Can you post the line which makes the compiler bark


  • Ultimate

    I've posted the entire proxy class for your review. I've highlighted the lines that are identified as the problem.

    Thanks for your assistance!

    //------------------------------------------------------------------------------
    // <auto-generated>
    // This code was generated by a tool.
    // Runtime Version:2.0.50727.42
    //
    // Changes to this file may cause incorrect behavior and will be lost if
    // the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Serialization;

    //
    // This source code was auto-generated by wsdl, Version=2.0.50727.42.
    //


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="LoginSoap", Namespace="http://www.cengentech.com")]
    public partial class Login : System.Web.Services.Protocols.SoapHttpClientProtocol {

    private System.Threading.SendOrPostCallback GetEnspireCompanyCodesOperationCompleted;

    private System.Threading.SendOrPostCallback AuthenticateOperationCompleted;

    /// <remarks/>
    public Login() {
    this.Url = "http://cengenxp6/enspiredbservices/login.asmx";
    }

    public Login(string URL)
    {
    this.Url = URL;
    }

    /// <remarks/>
    public event GetEnspireCompanyCodesCompletedEventHandler GetEnspireCompanyCodesCompleted;

    /// <remarks/>
    public event AuthenticateCompletedEventHandler AuthenticateCompleted;

    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.cengentech.com/GetEnspireCompanyCodes", RequestNamespace="http://www.cengentech.com", ResponseNamespace="http://www.cengentech.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public System.Data.DataSet GetEnspireCompanyCodes() {
    object[] results = this.Invoke("GetEnspireCompanyCodes", new object[0]);
    return ((System.Data.DataSet)(results[0]));
    }

    /// <remarks/>
    public System.IAsyncResult BeginGetEnspireCompanyCodes(System.AsyncCallback callback, object asyncState) {
    return this.BeginInvoke("GetEnspireCompanyCodes", new object[0], callback, asyncState);
    }

    /// <remarks/>
    public System.Data.DataSet EndGetEnspireCompanyCodes(System.IAsyncResult asyncResult) {
    object[] results = this.EndInvoke(asyncResult);
    return ((System.Data.DataSet)(results[0]));
    }

    /// <remarks/>
    public void GetEnspireCompanyCodesAsync() {
    this.GetEnspireCompanyCodesAsync(null);
    }

    /// <remarks/>
    public void GetEnspireCompanyCodesAsync(object userState) {
    if ((this.GetEnspireCompanyCodesOperationCompleted == null)) {
    this.GetEnspireCompanyCodesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetEnspireCompanyCodesOperationCompleted);
    }
    this.InvokeAsync("GetEnspireCompanyCodes", new object[0], this.GetEnspireCompanyCodesOperationCompleted, userState);
    }

    private void OnGetEnspireCompanyCodesOperationCompleted(object arg) {
    if ((this.GetEnspireCompanyCodesCompleted != null)) {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.GetEnspireCompanyCodesCompleted(this, new GetEnspireCompanyCodesCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
    }
    }

    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.cengentech.com/Authenticate", RequestNamespace="http://www.cengentech.com", ResponseNamespace="http://www.cengentech.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public System.Data.DataSet Authenticate(string pUsername, string pPassword, string pCompany) {
    object[] results = this.Invoke("Authenticate", new object[] {
    pUsername,
    pPassword,
    pCompany});
    return ((System.Data.DataSet)(results[0]));
    }

    /// <remarks/>
    public System.IAsyncResult BeginAuthenticate(string pUsername, string pPassword, string pCompany, System.AsyncCallback callback, object asyncState) {
    return this.BeginInvoke("Authenticate", new object[] {
    pUsername,
    pPassword,
    pCompany}, callback, asyncState);
    }

    /// <remarks/>
    public System.Data.DataSet EndAuthenticate(System.IAsyncResult asyncResult) {
    object[] results = this.EndInvoke(asyncResult);
    return ((System.Data.DataSet)(results[0]));
    }

    /// <remarks/>
    public void AuthenticateAsync(string pUsername, string pPassword, string pCompany) {
    this.AuthenticateAsync(pUsername, pPassword, pCompany, null);
    }

    /// <remarks/>
    public void AuthenticateAsync(string pUsername, string pPassword, string pCompany, object userState) {
    if ((this.AuthenticateOperationCompleted == null)) {
    this.AuthenticateOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAuthenticateOperationCompleted);
    }
    this.InvokeAsync("Authenticate", new object[] {
    pUsername,
    pPassword,
    pCompany}, this.AuthenticateOperationCompleted, userState);
    }

    private void OnAuthenticateOperationCompleted(object arg) {
    if ((this.AuthenticateCompleted != null)) {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.AuthenticateCompleted(this, new AuthenticateCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
    }
    }

    /// <remarks/>
    public new void CancelAsync(object userState) {
    base.CancelAsync(userState);
    }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    public delegate void GetEnspireCompanyCodesCompletedEventHandler(object sender, GetEnspireCompanyCodesCompletedEventArgs e);

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class GetEnspireCompanyCodesCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

    private object[] results;

    internal GetEnspireCompanyCodesCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
    base(exception, cancelled, userState) {
    this.results = results;
    }

    /// <remarks/>
    public System.Data.DataSet Result {
    get {
    this.RaiseExceptionIfNecessary();
    return ((System.Data.DataSet)(this.results[0]));
    }
    }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    public delegate void AuthenticateCompletedEventHandler(object sender, AuthenticateCompletedEventArgs e);

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class AuthenticateCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

    private object[] results;

    internal AuthenticateCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
    base(exception, cancelled, userState) {
    this.results = results;
    }

    /// <remarks/>
    public System.Data.DataSet Result {
    get {
    this.RaiseExceptionIfNecessary();
    return ((System.Data.DataSet)(this.results[0]));
    }
    }
    }


  • Rick Edwards

    This might help too ;o)


  • Cyril839

    Hi,

    Just re-generate the proxy in VS2005 from within a Pocket PC application - it should target the compact framework, and generate compatible code ;o)


  • Dave Waterworth

    Ernst,

    Thanks for taking the time to help me with this! I didn't think about loading it into a test application and seeing if it would compile. I know, that's the first thing I should have done but sometimes you can't see the trees for the forest. Anyway, I started a new VS2005 project and added it to the project and it compiled just as you stated. So, I went and looked at the version of the .NetFramework and sure enough it was set to version 1. I didn't think of the the version of the .NetFramework but it makes perfect sense that MS wouldn't automatically move to the next version now that I think about it.

    I changed the .NetFramework to version 2 and compiled and the problem is resolved. Well, almost, I have another issue because the client is really using the .NetCompactFramework which doesn't support

    System.ComponentModel.AsyncCompletedEventArgs

    Anyway, thanks so much for the help on this. I was beating my head up against the wall. Any suggestions on what to do about the new issue I also have a couple of other issues that I need answers to but I will post them on the forum instead of taking advantage of your generosity.

    Thanks again!


  • windypoint

    Ernst, the highlighted lines are the problems.

    Thanks!!!

    //------------------------------------------------------------------------------

    // <auto-generated>

    // This code was generated by a tool.

    // Runtime Version:2.0.50727.42

    //

    // Changes to this file may cause incorrect behavior and will be lost if

    // the code is regenerated.

    // </auto-generated>

    //------------------------------------------------------------------------------

    using System;

    using System.ComponentModel;

    using System.Data;

    using System.Diagnostics;

    using System.Web.Services;

    using System.Web.Services.Protocols;

    using System.Xml.Serialization;

    //

    // This source code was auto-generated by wsdl, Version=2.0.50727.42.

    //

    /// <remarks/>

    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]

    [System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.ComponentModel.DesignerCategoryAttribute("code")]

    [System.Web.Services.WebServiceBindingAttribute(Name="LoginSoap", Namespace="http://www.cengentech.com")]

    public partial class Login : System.Web.Services.Protocols.SoapHttpClientProtocol {

    private System.Threading.SendOrPostCallback GetEnspireCompanyCodesOperationCompleted;

    private System.Threading.SendOrPostCallback AuthenticateOperationCompleted;

    /// <remarks/>

    public Login() {

    this.Url = "http://cengenxp6/enspiredbservices/login.asmx";

    }

    public Login(string URL)

    {

    this.Url = URL;

    }

    /// <remarks/>

    public event GetEnspireCompanyCodesCompletedEventHandler GetEnspireCompanyCodesCompleted;

    /// <remarks/>

    public event AuthenticateCompletedEventHandler AuthenticateCompleted;

    /// <remarks/>

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.cengentech.com/GetEnspireCompanyCodes", RequestNamespace="http://www.cengentech.com", ResponseNamespace="http://www.cengentech.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

    public System.Data.DataSet GetEnspireCompanyCodes() {

    object[] results = this.Invoke("GetEnspireCompanyCodes", new object[0]);

    return ((System.Data.DataSet)(results[0]));

    }

    /// <remarks/>

    public System.IAsyncResult BeginGetEnspireCompanyCodes(System.AsyncCallback callback, object asyncState) {

    return this.BeginInvoke("GetEnspireCompanyCodes", new object[0], callback, asyncState);

    }

    /// <remarks/>

    public System.Data.DataSet EndGetEnspireCompanyCodes(System.IAsyncResult asyncResult) {

    object[] results = this.EndInvoke(asyncResult);

    return ((System.Data.DataSet)(results[0]));

    }

    /// <remarks/>

    public void GetEnspireCompanyCodesAsync() {

    this.GetEnspireCompanyCodesAsync(null);

    }

    /// <remarks/>

    public void GetEnspireCompanyCodesAsync(object userState) {

    if ((this.GetEnspireCompanyCodesOperationCompleted == null)) {

    this.GetEnspireCompanyCodesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetEnspireCompanyCodesOperationCompleted);

    }

    this.InvokeAsync("GetEnspireCompanyCodes", new object[0], this.GetEnspireCompanyCodesOperationCompleted, userState);

    }

    private void OnGetEnspireCompanyCodesOperationCompleted(object arg) {

    if ((this.GetEnspireCompanyCodesCompleted != null)) {

    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));

    this.GetEnspireCompanyCodesCompleted(this, new GetEnspireCompanyCodesCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));

    }

    }

    /// <remarks/>

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.cengentech.com/Authenticate", RequestNamespace="http://www.cengentech.com", ResponseNamespace="http://www.cengentech.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

    public System.Data.DataSet Authenticate(string pUsername, string pPassword, string pCompany) {

    object[] results = this.Invoke("Authenticate", new object[] {

    pUsername,

    pPassword,

    pCompany});

    return ((System.Data.DataSet)(results[0]));

    }

    /// <remarks/>

    public System.IAsyncResult BeginAuthenticate(string pUsername, string pPassword, string pCompany, System.AsyncCallback callback, object asyncState) {

    return this.BeginInvoke("Authenticate", new object[] {

    pUsername,

    pPassword,

    pCompany}, callback, asyncState);

    }

    /// <remarks/>

    public System.Data.DataSet EndAuthenticate(System.IAsyncResult asyncResult) {

    object[] results = this.EndInvoke(asyncResult);

    return ((System.Data.DataSet)(results[0]));

    }

    /// <remarks/>

    public void AuthenticateAsync(string pUsername, string pPassword, string pCompany) {

    this.AuthenticateAsync(pUsername, pPassword, pCompany, null);

    }

    /// <remarks/>

    public void AuthenticateAsync(string pUsername, string pPassword, string pCompany, object userState) {

    if ((this.AuthenticateOperationCompleted == null)) {

    this.AuthenticateOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAuthenticateOperationCompleted);

    }

    this.InvokeAsync("Authenticate", new object[] {

    pUsername,

    pPassword,

    pCompany}, this.AuthenticateOperationCompleted, userState);

    }

    private void OnAuthenticateOperationCompleted(object arg) {

    if ((this.AuthenticateCompleted != null)) {

    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));

    this.AuthenticateCompleted(this, new AuthenticateCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));

    }

    }

    /// <remarks/>

    public new void CancelAsync(object userState) {

    base.CancelAsync(userState);

    }

    }

    /// <remarks/>

    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]

    public delegate void GetEnspireCompanyCodesCompletedEventHandler(object sender, GetEnspireCompanyCodesCompletedEventArgs e);

    /// <remarks/>

    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]

    [System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.ComponentModel.DesignerCategoryAttribute("code")]

    public partial class GetEnspireCompanyCodesCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

    private object[] results;

    internal GetEnspireCompanyCodesCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :

    base(exception, cancelled, userState) {

    this.results = results;

    }

    /// <remarks/>

    public System.Data.DataSet Result {

    get {

    this.RaiseExceptionIfNecessary();

    return ((System.Data.DataSet)(this.results[0]));

    }

    }

    }

    /// <remarks/>

    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]

    public delegate void AuthenticateCompletedEventHandler(object sender, AuthenticateCompletedEventArgs e);

    /// <remarks/>

    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]

    [System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.ComponentModel.DesignerCategoryAttribute("code")]

    public partial class AuthenticateCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {

    private object[] results;

    internal AuthenticateCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :

    base(exception, cancelled, userState) {

    this.results = results;

    }

    /// <remarks/>

    public System.Data.DataSet Result {

    get {

    this.RaiseExceptionIfNecessary();

    return ((System.Data.DataSet)(this.results[0]));

    }

    }

    }


  • Web Service Partial Class