2016-09-09 3 views
0

SOAP 기반 자바 웹 서비스를 호출하기위한 C# 코드를 작성 중입니다. wsdl에서 내부 클래스를 만들었을 때 비동기 버전이있는 모든 동기화 끝점도 종료되었습니다. 지금까지 비동기 호출이 필요하지 않으므로이를 무시했습니다. 긴 이야기를 짧게하기 위해 - 지금 필요합니다.비동기 자바 웹 서비스 호출하기

internal static class WebServiceAsyncExtensions 
{ 
    internal static Task<getLookupListCompletedEventArgs> LookupAsync(this WebService ws, string lookupKey) 
    { 
     var taskCreateSource = CreateSource<getLookupListCompletedEventArgs>(null); 
     ws.getLookupListCompleted += (sender, e) => TransferCompletion(taskCreateSource, e,() => e, null); 
     ws.getLookupListAsync(lookupKey); 
     return taskCreateSource.Task; 
    } 
    private static TaskCompletionSource<T> CreateSource<T>(object state) => new TaskCompletionSource<T>(state, TaskCreationOptions.None); 
    private static void TransferCompletion<T>(TaskCompletionSource<T> taskCreateSource, AsyncCompletedEventArgs e, Func<T> getResult, Action unregisterHandler) 
    { 
     if (e.UserState != taskCreateSource) 
      return; 

     if (e.Cancelled) 
      taskCreateSource.TrySetCanceled(); 
     else if (e.Error != null) 
      taskCreateSource.TrySetException(e.Error); 
     else 
      taskCreateSource.TrySetResult(getResult()); 

     unregisterHandler?.Invoke(); 
    } 
} 

그리고 시험 :

public class Lookups : IWebRepository 
{ 
    private readonly WebService _ws; 

    public Lookups() 
    { 
     _ws = WebServiceExtended.Instance.Endpoint; 
    } 

    public IEnumerable<string> Cities() => _ws.getLookupList("Cities").Select(o => o as lookup).Select(l => l.Name); 
    public async Task<IEnumerable<string>> CitiesAsync() 
    { 
     var results = await _ws.LookupAsync("Cities"); 
     return results.Result.Select(o => o as lookup).Select(a => a.Name); 
    } 
} 

내가이 확장을 만든 : 여기

내가 해봤과 (MS) 단위 테스트는 테스트 무엇의 예입니다
[TestMethod] 
public async Task Lookup_Async_Cities_Succeeds() 
{ 
    var response = await _ws.RepositoryLookups.CitiesAsync(); 
    Assert.IsInstanceOfType(response, typeof(IEnumerable<string>)); 
    Assert.IsTrue(response != null); 
    Assert.IsTrue(response.Any()); 
} 

생성 된 (wsdl) 코드를 보면 다음과 같습니다.

/// <remarks/> 
public void getLookupListAsync(string arg0) { 
    this.getLookupListAsync(arg0, null); 
} 

/// <remarks/> 
public void getLookupListAsync(string arg0, object userState) { 
    if ((this.getLookupListOperationCompleted == null)) { 
     this.getLookupListOperationCompleted = new System.Threading.SendOrPostCallback(this.OngetLookupListOperationCompleted); 
    } 
    this.InvokeAsync("getLookupList", new object[] { 
       arg0}, this.getLookupListOperationCompleted, userState); 
} 

내가 겪고있는 도전은 내가 라 라 땅으로 돌아서 전화를 걸었을 때 응답을 보내지 않는 것입니다. Sync 버전을 테스트/호출 할 때 예상되는 응답을 얻습니다. 이것은 수년간 사용해 온 웹 서비스이며 이제는 C# 측면에서 일부 기능을 확장하고 있습니다.

내가 누락 된 항목이 있습니까? 더 나은 아직; 나는 무엇이 없는가?!

+0

[Fiddler] (http://www.telerik.com/fiddler)와 같은 것을 사용해보십시오. –

답변

0

JAVA 웹 서비스는이 경우 모든 엔드 포인트에서 async를 인식하지 못한다는 사실이 밝혀졌습니다. VS에서 Microsoft 도구로 만든 모든 종단점 중에서 비동기식 인 종단점 2 개를 발견했습니다. 교훈 : 그것이 정의 되었기 때문에 그것이 존재한다는 것을 의미하지는 않습니다.