How to call a java webservice via c#

Last post 07-13-2009 10:40 AM by hu.brett. 2 replies.

Sort Posts:

  • How to call a java webservice via c#

    07-12-2009, 7:07 PM
    • Member
      point Member
    • hu.brett
    • Member since 07-12-2009, 6:55 PM
    • Posts 2

     I have java webservice and I generate c# code from the wsdl file by adding a web reference. The generated code is attached. I am a new .net guy. Could anybody tell me how to use this generated code to synchronized call the java webservice method {Boolean validatera(int id){}}. Thanks in advance.

     

    #pragma warning disable 1591
    
    namespace databaseConnectionTest {
        using System.Diagnostics;
        using System.Web.Services;
        using System.ComponentModel;
        using System.Web.Services.Protocols;
        using System;
        using System.Xml.Serialization;
        
        
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.3053")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.ComponentModel.DesignerCategoryAttribute("code")]
        [System.Web.Services.WebServiceBindingAttribute(Name="raValidationServiceSoap11Binding", Namespace="http://service.york.water.sc.com")]
        public partial class raValidationService : System.Web.Services.Protocols.SoapHttpClientProtocol {
            
            private System.Threading.SendOrPostCallback validateraOperationCompleted;
            
            private bool useDefaultCredentialsSetExplicitly;
            
            /// <remarks/>
            public raValidationService() {
                this.Url = global::databaseConnectionTest.Properties.Settings.Default.databaseConnectionTest_raValidationService;
                if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                    this.UseDefaultCredentials = true;
                    this.useDefaultCredentialsSetExplicitly = false;
                }
                else {
                    this.useDefaultCredentialsSetExplicitly = true;
                }
            }
            
            public new string Url {
                get {
                    return base.Url;
                }
                set {
                    if ((((this.IsLocalFileSystemWebService(base.Url) == true) 
                                && (this.useDefaultCredentialsSetExplicitly == false)) 
                                && (this.IsLocalFileSystemWebService(value) == false))) {
                        base.UseDefaultCredentials = false;
                    }
                    base.Url = value;
                }
            }
            
            public new bool UseDefaultCredentials {
                get {
                    return base.UseDefaultCredentials;
                }
                set {
                    base.UseDefaultCredentials = value;
                    this.useDefaultCredentialsSetExplicitly = true;
                }
            }
            
            /// <remarks/>
            public event validateraCompletedEventHandler validateraCompleted;
            
            /// <remarks/>
            [System.Web.Services.Protocols.SoapDocumentMethodAttribute("urn:validatera", RequestNamespace="http://service.york.water.sc.com", ResponseNamespace="http://service.york.water.sc.com", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
            public void validatera(int raId, [System.Xml.Serialization.XmlIgnoreAttribute()] bool raIdSpecified, out bool @return, [System.Xml.Serialization.XmlIgnoreAttribute()] out bool returnSpecified) {
                object[] results = this.Invoke("validatera", new object[] {
                            raId,
                            raIdSpecified});
                @return = ((bool)(results[0]));
                returnSpecified = ((bool)(results[1]));
            }
            
            /// <remarks/>
            public void validateraAsync(int raId, bool raIdSpecified) {
                this.validateraAsync(raId, raIdSpecified, null);
            }
            
            /// <remarks/>
            public void validateraAsync(int raId, bool raIdSpecified, object userState) {
                if ((this.validateraOperationCompleted == null)) {
                    this.validateraOperationCompleted = new System.Threading.SendOrPostCallback(this.OnvalidateraOperationCompleted);
                }
                this.InvokeAsync("validatera", new object[] {
                            raId,
                            raIdSpecified}, this.validateraOperationCompleted, userState);
            }
            
            private void OnvalidateraOperationCompleted(object arg) {
                if ((this.validateraCompleted != null)) {
                    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                    this.validateraCompleted(this, new validateraCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.comncelled, invokeArgs.UserState));
                }
            }
            
            /// <remarks/>
            public new void CancelAsync(object userState) {
                base.comncelAsync(userState);
            }
            
            private bool IsLocalFileSystemWebService(string url) {
                if (((url == null) 
                            || (url == string.Empty))) {
                    return false;
                }
                System.Uri wsUri = new System.Uri(url);
                if (((wsUri.Port >= 1024) 
                            && (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
                    return true;
                }
                return false;
            }
        }
        
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.3053")]
        public delegate void validateraCompletedEventHandler(object sender, validateraCompletedEventArgs e);
        
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.3053")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.ComponentModel.DesignerCategoryAttribute("code")]
        public partial class validateraCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
            
            private object[] results;
            
            internal validateraCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                    base(exception, cancelled, userState) {
                this.results = results;
            }
            
            /// <remarks/>
            public bool @return {
                get {
                    this.RaiseExceptionIfNecessary();
                    return ((bool)(this.results[0]));
                }
            }
            
            /// <remarks/>
            public bool returnSpecified {
                get {
                    this.RaiseExceptionIfNecessary();
                    return ((bool)(this.results[1]));
                }
            }
        }
    }
    
    #pragma warning restore 1591


    Filed under:
  • Re: How to call a java webservice via c#

    07-12-2009, 10:58 PM
    Answer

    using (raValidatorService svc = new raValidatorService()) {
        bool returnValue, returnValueSpecified;
        svc.validatera(raId, true, out returnValue, out returnVaueSpecified);
        if (returnValueSpecified)
            return returnValue;
        else
            return false;  // or whatever default you like
    }
    


    John Saunders
  • Re: How to call a java webservice via c#

    07-13-2009, 10:40 AM
    • Member
      point Member
    • hu.brett
    • Member since 07-12-2009, 6:55 PM
    • Posts 2

     Thanks. I get it.

Page 1 of 1 (3 items)