Announcement

Collapse
No announcement yet.

Implementierung asynchroner Web Service

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Implementierung asynchroner Web Service

    Hi ihr..
    ich habe Probleme einen asynchronen Web Service mit C# und .Net Framework 4.5 zu realisieren. Leider habe ich bisher noch keine Lösungen gefunden, wie ich die Methodenaufrufe und Funktionen async-gerecht implementieren kann. Vielleicht hat einer von euch schon Erfahrung damit..

    Code:
    var binding = new BasicHttpBinding();
    binding.MaxReceivedMessageSize = int.MaxValue;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
    binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    var address = new EndpointAddress("http://server:port/Webservice");
    
    WebserviceClient client = new WebserviceClient(binding, address);
    client.ClientCredentials.UserName.UserName = "UNAME";
    client.ClientCredentials.UserName.Password = "PWORD";
    
    WebserviceRequest request = new WebserviceRequest();
    request.Nummer = inputNumme.Text;                                     //aus TextBox
    
    WebserviceResponse response = await client.WebserviceAsync(request);
    
    InfoKlasse Rueckmeldung = response.Return[0];
    var _message = Rueckmeldung.Message;
    
    showListBlock.Text = _message;                                          //in Ausgabe-TextBox

    Vielen Dank für eure Mühen..
    Andi

  • #2
    Beispiel: (while(true) damit die Methode nicht verlassen wird.)
    Es werde Int32-Werte über einen Zeitraum geliefert, bzw. angefragt.

    Code:
       
    [STAThread]
    static void Main(string[] args)
    { 
                 using (WebReference1.Service1 svr = new WebReference1.Service1())
                {
                    svr.MyWebServiceMethodCompleted += new MyWebServiceMethodCompletedEventHandler(svr_MyWebServiceMethodCompleted);
                    svr.MyWebServiceMethodAsync(DateTime.Now.AddDays(-10), DateTime.Now);
                }
    
                while (true)
                    System.Threading.Thread.Sleep(10);
    }
    
    
            static void svr_MyWebServiceMethodCompleted(object sender, MyWebServiceMethodCompletedEventArgs e)
            {
                throw new NotImplementedException();
            }

    wird von VisualStudio erzeugt:


    Code:
       
     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
     [System.Diagnostics.DebuggerStepThroughAttribute()]
     [System.ComponentModel.DesignerCategoryAttribute("code")]
     [System.Web.Services.WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://MyService1.org/")]
     public partial class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol 
    {
            [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://MyWebService1.org/MyWebServiceMethod", RequestNamespace="http://MyWebService1.org/", ResponseNamespace="http://MyWebService1.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
            public int[] MyWebServiceMethod(System.DateTime start, System.DateTime end) 
            {
                object[] results = this.Invoke("MyWebServiceMethod", new object[] {start,end});
                return ((int[])(results[0]));
            }
            
            public void MyWebServiceMethodAsync(System.DateTime start, System.DateTime end) 
            {
                this.MyWebServiceMethodAsync(start, end, null);
            }
            
    
            public void MyWebServiceMethodAsync(System.DateTime start, System.DateTime end, object userState) 
            {
                if ((this.MyWebServiceMethodOperationCompleted == null)) 
                    this.MyWebServiceMethodOperationCompleted = new System.Threading.SendOrPostCallback(this.OnMyWebServiceMethodOperationCompleted);
    
                this.InvokeAsync("MyWebServiceMethod", new object[] {start,end}, this.MyWebServiceMethodOperationCompleted, userState);
            }
            
            private void OnMyWebServiceMethodOperationCompleted(object arg) 
            {
                if ((this.MyWebServiceMethodCompleted != null)) {
                    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                    this.MyWebServiceMethodCompleted(this, new MyWebServiceMethodCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
    }
    
    
    
    
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class MyWebServiceMethodCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs 
    {
            
            private object[] results;
            
            internal MyWebServiceMethodCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :  base(exception, cancelled, userState) 
            {
                this.results = results;
            }
            
            public int[] Result 
            {
                  get
                    {
                            this.RaiseExceptionIfNecessary();
                            return ((int[])(this.results[0]));
                    }
            }
    }

    [/CODE]

    Comment


    • #3
      hm.. danke für deine Hilfe..... aber ehrlich gesagt kann ich damit nicht allzu viel anfangen :/ Hilft dir vllt DAS weiter bei meiner Problemstellung!?
      Danke nochmals..

      Code:
      Der generierte Async-Aufruf:
      
              public System.Threading.Tasks.Task<WS_weather.ZAL_ENTRYSHEET_DELETE.EntrysheetDeleteResponse> EntrysheetDeleteAsync(WS_weather.ZAL_ENTRYSHEET_DELETE.EntrysheetDeleteRequest request) {
                  return base.Channel.EntrysheetDeleteAsync(request);
              }
      
      
      Der generierte Request:
          [System.Diagnostics.DebuggerStepThroughAttribute()]
          [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
          [System.ServiceModel.MessageContractAttribute(WrapperName="EntrysheetDelete", WrapperNamespace="urn:sap-com:document:sap:soap:functions:mc-style", IsWrapped=true)]
          public partial class EntrysheetDeleteRequest {
              
              [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", Order=0)]
              [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
              public string Entrysheet;
              
              [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", Order=1)]
              [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
              [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
              public WS_weather.ZAL_ENTRYSHEET_DELETE.Bapiret2[] Return;
              
              public EntrysheetDeleteRequest() {
              }
              
              public EntrysheetDeleteRequest(string Entrysheet, WS_weather.ZAL_ENTRYSHEET_DELETE.Bapiret2[] Return) {
                  this.Entrysheet = Entrysheet;
                  this.Return = Return;
              }
          }
      
      
      Der generierte Response:
          public partial class EntrysheetDeleteResponse {
              
              [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", Order=0)]
              [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
              [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
              public WS_weather.ZAL_ENTRYSHEET_DELETE.Bapiret2[] Return;
              
              public EntrysheetDeleteResponse() {
              }
              
              public EntrysheetDeleteResponse(WS_weather.ZAL_ENTRYSHEET_DELETE.Bapiret2[] Return) {
                  this.Return = Return;
              }
          }

      Comment

      Working...
      X