2014-12-16 14 views
1

웹 서비스에 익숙하지 않고 WSHttpBinding을 사용하여 웹 서비스를 사용하는 기존 wpf C# 데스크톱 응용 프로그램에 basicHTTPBinding을 구현해야합니다.웹 서비스 basicHTTPBinding

<bindings> 
    <wsHttpBinding> 
    <binding name="HI_SSLBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" /> 
     <message clientCredentialType="UserName" negotiateServiceCredential="True" establishSecurityContext="True" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 

    <basicHttpBinding> 
    <binding name="HI_BasicBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
     <security mode="Transport"> 
     <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" /> 
     </security> 
     <readerQuotas maxStringContentLength="2147483647" /> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

<services> 
    <service name="HIWebService.HIService" behaviorConfiguration="SecureBehave"> 
    <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="HI_BasicBinding" contract="HILib.HIService.IHIService"></endpoint> 
    <endpoint address="ws" binding="wsHttpBinding" bindingConfiguration="HI_SSLBinding" contract="HILib.HIService.IHIService"></endpoint> 
    <host> 
     <baseAddresses> 
     <add baseAddress="https://10.50.1.85:1345/HI/HIService.svc" /> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 

의 WPF C# 데스크톱 응용 프로그램이 웹 서비스에 바로있는 wsHttpBinding을 소비하는 App.configer 있습니다 웹 서비스는 이미 웹 서비스에 web.config 파일에 다음과 같은 두 바인딩으로 구성되어 다음과 같이

System.ServiceModel.WSHttpBinding wsHTTPSBinding = new System.ServiceModel.WSHttpBinding(); 
      wsHTTPSBinding.Name = "HIBridge_SSLBinding"; 
      wsHTTPSBinding.OpenTimeout = TimeSpan.FromMinutes(1); 
      wsHTTPSBinding.CloseTimeout = TimeSpan.FromMinutes(1); 
      wsHTTPSBinding.SendTimeout = TimeSpan.FromMinutes(1); 
      wsHTTPSBinding.ReceiveTimeout = TimeSpan.FromMinutes(10); 
      wsHTTPSBinding.BypassProxyOnLocal = false; 
      wsHTTPSBinding.TransactionFlow = false; 
      wsHTTPSBinding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; 
      wsHTTPSBinding.MaxBufferPoolSize = 2147483647; 
      wsHTTPSBinding.MaxReceivedMessageSize = 2147483647; 
      wsHTTPSBinding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; 
      wsHTTPSBinding.TextEncoding = Encoding.UTF8; 
      wsHTTPSBinding.UseDefaultWebProxy = true; 
      wsHTTPSBinding.AllowCookies = false; 


      wsHTTPSBinding.ReliableSession.Ordered = true; 
      wsHTTPSBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10); 
      wsHTTPSBinding.ReliableSession.Enabled = false; 

      wsHTTPSBinding.Security.Mode = System.ServiceModel.SecurityMode.TransportWithMessageCredential; 
      wsHTTPSBinding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Certificate; 
      wsHTTPSBinding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; 
      wsHTTPSBinding.Security.Transport.Realm = ""; 
      wsHTTPSBinding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.UserName; 
      wsHTTPSBinding.Security.Message.NegotiateServiceCredential = true; 
      wsHTTPSBinding.Security.Message.EstablishSecurityContext = true; 
      System.ServiceModel.EndpointAddress endpointAddress = null; 

      endpointAddress = new System.ServiceModel.EndpointAddress(string.Format("https://10.50.1.85:1345/HI/HIService.svc/ws"); 

어떻게 :

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
    <wsHttpBinding> 
    <binding name="HI_SSLBinding" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
     messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
     allowCookies="false"> 

     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 

     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" /> 
     <message clientCredentialType="UserName" negotiateServiceCredential="True" establishSecurityContext="True"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<behaviors> 
    <endpointBehaviors> 
    <behavior> 
     <clientCredentials> 
     <serviceCertificate> 
      <authentication certificateValidationMode="PeerOrChainTrust"/> 
     </serviceCertificate> 
     </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 
<client> 
    <endpoint address="https://10.50.1.85:1345/HI/HIService.svc" binding="wsHttpBinding" bindingConfiguration="HI_SSLBinding" contract="HILib.HIService.IHIService"> 

    </endpoint> 
</client> 
</system.serviceModel> 
</configuration> 

하는 응용 프로그램이있는 wsHttpBinding을 소비 자 할 때 다음과 같은 수행 BasicHttpBinding에 대한 App.configer를 구성하고 C# wpf 응용 프로그램에서도이 바인딩을 호출하는 방법은 무엇입니까?

답변

1

시도해 볼 수 있습니까?

의 app.config

<configuration> 
    <system.serviceModel> 
     <bindings> 
     <basicHttpBinding> 
      <binding name="basicHttp_HI_SSLBinding" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 

      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />          
      <security mode="TransportWithMessageCredential"> 
       <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" /> 
       <message clientCredentialType="UserName" /> 
      </security> 
      </binding> 
     </basicHttpBinding> 
     </bindings> 
     <behaviors> 
     <endpointBehaviors>   
      <behavior name="endpointBehavivor"> 
      <clientCredentials> 
       <serviceCertificate> 
       <authentication certificateValidationMode="PeerOrChainTrust"/> 
       </serviceCertificate> 
      </clientCredentials> 
      </behavior> 
     </endpointBehaviors> 
     </behaviors> 
     <client> 
     <endpoint address="https://10.50.1.85:1345/HI/HIService.svc" behaviorConfiguration="endpointBehavivor" binding="basicHttpBinding" bindingConfiguration="basicHttp_HI_SSLBinding" contract="HILib.HIService.IHIService"> 
     </endpoint> 
     </client> 
    </system.serviceModel> 
    </configuration> 

과는

//define binding 
      BasicHttpBinding myBinding = new BasicHttpBinding(); 
      myBinding.Name = "basicHttp_HI_SSLBinding"; 
      myBinding.OpenTimeout = TimeSpan.FromMinutes(1); 
      myBinding.CloseTimeout = TimeSpan.FromMinutes(1); 
      myBinding.SendTimeout = TimeSpan.FromMinutes(1); 
      myBinding.ReceiveTimeout = TimeSpan.FromMinutes(10); 
      myBinding.BypassProxyOnLocal = false; 
      myBinding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard; 
      myBinding.MaxBufferPoolSize = 2147483647; 
      myBinding.MaxReceivedMessageSize = 2147483647; 
      myBinding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text; 
      myBinding.TextEncoding = Encoding.UTF8; 
      myBinding.UseDefaultWebProxy = true; 
      myBinding.AllowCookies = false; 
      myBinding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; 
      myBinding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Certificate; 
      myBinding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None; 
      myBinding.Security.Transport.Realm = ""; 

      //define endpoint url    
      EndpointAddress myEndpoint = new EndpointAddress("https://10.50.1.85:1345/HI/HIService.svc/ws"); 

      //Use channle factory to autogenerate proxy class 
      ChannelFactory<HILib.HIService.IHIService> myChannelFactory = new ChannelFactory<HILib.HIService.IHIService>(myBinding, myEndpoint); 
      HILib.HIService.IHIService HIService = myChannelFactory.CreateChannel(); 

      //and call it 
      var result = HIService.SomeMethodcall(); 

      ((IClientChannel)HIService).Close(); 
      myChannelFactory.Close(); 
+0

내가 myChannelFactory.Credentials.UserName.UserName = "USERNAME"를 추가 소모; ChannelFactory를 생성 한 직후에 내가 사용자 이름을 제공하지 않았다는 오류가 발생했기 때문에. wsHTTPSBinding에 사용 된 동일한 사용자 이름을 입력합니다. 자격 증명 사용자 이름을 추가 한 후에도 여전히 작동하지 않는 경우 다음 오류가 표시됩니다. HTTP 요청이 '익명'클라이언트 인증 스키마와 함께 금지되었습니다. 내가 뭘 잘못하고 있는지 알아? app.config에서 구성하지 않고도 소비 할 수 있습니까? – user3614070