2017-01-11 3 views
0

제공된 WSDL 파일에서 WCF 서비스 참조를 만들었습니다. C#에서 나는 기본 바인딩과 프록시 클라이언트의 인스턴스를 생성하고 필요한 방법이라고했습니다웹 서비스 호출 오류

: 내가 'getNewOrderNumber'메서드를 호출 할 때 불행하게도 나는 상당히 도움이되지 않는 오류가 발생하고있어

public static bool main() 
    { 
     Debugger.Launch(); 
     var binding = new BasicHttpsBinding(); 

     binding.Security.Mode = BasicHttpsSecurityMode.Transport; 
     binding.TextEncoding = System.Text.Encoding.UTF8; 

     var remoteAddress = new System.ServiceModel.EndpointAddress("https://tester.mysite.de:8443/webservice/OrderNumber"); 

     using (var orderNumberClient = new orderNumberClient(new System.ServiceModel.BasicHttpBinding(BasicHttpSecurityMode.Transport), remoteAddress)) 
     { 
      string IDSystem = "123"; 
      string IDOSystem = "abc"; 

      //set timeout 
      orderNumberClient.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 10000); 
      orderNumberClient.ClientCredentials.UserName.UserName = "test"; 
      orderNumberClient.ClientCredentials.UserName.Password = "test"; 

      //call web service method 
      string productResponse = orderNumberClient.getNewOrderNumber(IDSystem, "01", IDOSystem); ; 

      MessageBox.Show(productResponse); 
     } 

     return true; 
    } 

System.Reflection.TargetInvocationException : Ein Aufrufziel hatAusnahmefehler verursacht. ---> System.ServiceModel.FaultException : WebService를 처리 예외

서버 스택 트레이스 :

BEI System.ServiceModel.Channels.ServiceChannel.HandleReply (ProxyOperationRuntime 동작 ProxyRpc & RPC)

System.ServiceModel.Channels.ServiceChannel.Call (String action, Boolean oneway, ProxyOperationRuntime operation, Object [] ins Object [] outs, TimeSpan timeout)

BEI System.ServiceModel.Channels.ServiceChannelProxy.InvokeService (IMethodCallMessage methodCall을, ProxyOperationRuntime 작업)

...

그 SOAPUI에서 잘 작동 것처럼 웹 서비스 측에 오류가 아니다, 바인딩에 뭔가 빠져있을 가능성이 있습니까?

웹 서비스에 대해 더 잘 알고있는 누군가가 근본 원인을 밝힐 수 있기를 바랍니다.

+0

나는 이것이 매우 모호한 예외는 동의합니다. 나는이 특별한 사람이 더 도움이 될 내면의 예외를 가져야한다고 생각한다. 주 : 그것은 몇 층 깊이로 중첩 될 수 있습니다. 더 이상 가질 때까지 내부 예외를 확인하십시오. – Vahlkron

+0

내부 예외의 물질을 볼 수있는 것이 아무것도 없었습니다. (운좋게도 클라이언트에서 내가 필요한 헤더가 누락되었음을 알았습니다!) 답변을 게시 할 것입니다. –

답변

0

전화와 함께 '인증'헤더를 보내지 않은 것으로 나타났습니다. 이 문제를 극복하기 위해 내가 실제 웹 서비스 메서드 호출을하기 전에 프록시 인스턴스 내부 채널에 필요한 HttpRequestMessageProperty을 추가 OperationContextScope 클래스를 사용 :

   using (OperationContextScope scope = new OperationContextScope(orderNumberClient.InnerChannel)) 
       { 
        var httpRequestProperty = new HttpRequestMessageProperty(); 
        httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + 
        Convert.ToBase64String(Encoding.ASCII.GetBytes(orderNumberClient.ClientCredentials.UserName.UserName + ":" + 
        orderNumberClient.ClientCredentials.UserName.Password)); 
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty; 

        string Response = orderNumberClient.getNewOrderNumber(IDSystem, "01", IDOSystem); 
       }