2012-10-03 2 views
1

샘플의 간단한 C# 웹 서비스에 문제가 있습니다. 내가 그렇게 같은 클라이언트에서 서비스를 소비비동기 웹 서비스의 EndInvoke가 쓸모없는 값을 반환합니다.

public delegate string LengthyProcedureAsyncStub(int milliseconds); 

    public class MyState 
    { 
     public string text; 
     public object previousState; 
     public LengthyProcedureAsyncStub asyncStub; 
    } 

    [WebMethod] 
    public IAsyncResult BeginLengthyProcedure(int milliseconds, AsyncCallback cb, object s) 
    { 
     LengthyProcedureAsyncStub stub = new LengthyProcedureAsyncStub(LengthyProcedure); 
     MyState ms = new MyState(); 
     ms.previousState = s; 
     ms.asyncStub = stub; 
     return stub.BeginInvoke(milliseconds, cb, ms); 
    } 

    public string LengthyProcedure(int milliseconds) 
    { 
     System.Threading.Thread.Sleep(milliseconds); 
     return "Success"; 
    } 

    [WebMethod] 
    public string EndLengthyProcedure(IAsyncResult call) 
    { 
     MyState ms = (MyState)call.AsyncState; 
     string result = ms.asyncStub.EndInvoke(call); 
     return result;//ms.text; 
    } 

: 이 내 서버 측 코드

private void button1_Click(object sender, EventArgs e) 
    { 

     Waiter(5000); 

    } 

    private void Waiter(int milliseconds) 
    { 
     asyncProcessor.Service1SoapClient sendReference; 
     sendReference = new asyncProcessor.Service1SoapClient(); 
     sendReference.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 
     sendReference.BeginLengthyProcedure(milliseconds, ServiceCallBack, null); 

    } 

    private void ServiceCallBack(IAsyncResult result) 
    { 
     string strResult = result.ToString(); 
    } 

문제는 값의로 클라이언트 변수 strResult 대신, "성공"을 가지고 있어야한다는 것입니다 그것은이 있습니다 : "System.ServiceModel.Channels.ServiceChannel + SendAsyncResult". 내가 뭘 잘못하고 간과하니? 시간 :

+1

스택 오버플로에 오신 것을 환영합니다! 태그는 독자적으로 사용됩니다. 개별 태그를 결합한다고해서 추가 의미가 부여되지는 않습니다. 예를 들어,'web'과'service'를 조합한다고해서 웹 서비스에 관해 말하는 것은 아닙니다. – Charles

+0

@Charles 챨스를 설명해 주셔서 감사합니다. 미래를 염두에 두겠습니다. – user1417947

답변

0

이리저리 사전에

덕분에 당신은 sendReference 대신 null을 통과해야합니다.

private void Waiter(int milliseconds) 
{ 
    asyncProcessor.Service1SoapClient sendReference; 
    sendReference = new asyncProcessor.Service1SoapClient(); 
    sendReference.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 
    sendReference.BeginLengthyProcedure(milliseconds, ServiceCallBack, sendReference); 

} 

private void ServiceCallBack(IAsyncResult result) 
{ 
    asyncProcessor.Service1SoapClient sendReference = result.AsyncState as asyncProcessor.Service1SoapClient; 
    string strResult = sendReference.EndLengthyProcedure(result); 
} 
+0

답변 해 주신 Grzegorz에게 감사드립니다. 그것으로 문제가 해결되었습니다. 나는 변화를 한 후에 또 다른 작은 세부 사항을 가지고 있었다. "HTTP 요청은 클라이언트 인증 체계 '익명'으로 인증되지 않았습니다. 서버에서받은 인증 헤더는 '협상, NTLM'이었습니다. 익명 액세스를 활성화하여 IIS에서 해결할 수 있지만 Google 정책에 위배됩니다. 그래서 app.config의 다른 바인딩을 TransportCredentialOnly를 사용하도록 변경하고 훌륭하게 작동했습니다. 다시 한번 감사드립니다. – user1417947

관련 문제