2014-02-27 2 views
0

오늘 WCF 서비스를 변환하여 BasicHttpBinding 대신 WSHttpBinding을 사용했습니다. 아직 개발 단계에 있으므로 자체 서명 인증서를 사용하고 있습니다. 내가 본 예제가있다. Here기본값 개체 값이

예제와 같이 작동하도록 코드를 얻은 후에 (다운로드 할 수있는 코드에서 configs 예제를 따른다), 나는 그랬던 것처럼 채널 팩토리를 사용하기로 결정했다. 전에.

이제 WCF 메서드를 호출 할 때 내가 보내고있는 개체가 예상 값으로 채워지는 것을 분명히 볼 수 있지만 WCF쪽으로 들어가면 그 값이 기본값이됩니다. 예를 들어 Guid는 Empty Guid이고 Int의 값은 0입니다.

어떤 원인 일 수 있습니까? 의 Web.config에서

: 내가 예를 들어, 클라이언트 측에서 서비스를 호출 할 때

<add key="ClientCertificate" value="WcfClient" /> 
<add key="ServerCertificate" value="WcfServer" /> 

<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="CustomBehavior"> 
      <clientCredentials> 
      <clientCertificate findValue="WcfClient" 
           x509FindType="FindBySubjectName" 
           storeLocation="CurrentUser" 
           storeName="My" /> 
      <serviceCertificate> 
       <authentication certificateValidationMode="PeerTrust"/> 
      </serviceCertificate> 
      </clientCredentials> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IDocumentsService" closeTimeout="00:10:00" 
      openTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" 
      maxReceivedMessageSize="2147483647" messageEncoding="Mtom" allowCookies="true"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security mode="Message"> 
       <transport clientCredentialType="Windows" proxyCredentialType="None" 
        realm="" /> 
       <message clientCredentialType="Certificate" negotiateServiceCredential="true" 
        algorithmSuite="Default" establishSecurityContext="true" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:58790/DocumentsService.svc" 
       binding="wsHttpBinding" 
       bindingConfiguration="WSHttpBinding_IDocumentsService" 
       contract="DocumentsService.IDocumentsService" 
       name="WSHttpBinding_IDocumentsService" 
       behaviorConfiguration="CustomBehavior"> 
     <identity> 
      <dns value="WcfServer" /> 
     </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 

이 내 채널 공장

public static class ServiceObjects 
{ 
    public static IDocumentsService DocumentsSVC { get { return GetDocServiceClient(); } } 


    #region Private Members 
    private static WSHttpBinding _DMBinding = new WSHttpBinding("WSHttpBinding_IDocumentsService"); 
    private static EndpointIdentity _DMIdentity = EndpointIdentity.CreateDnsIdentity(ConfigurationManager.AppSettings.Get("ServerCertificate")); 
    private static EndpointAddress _DMEndpoint = new EndpointAddress(new Uri(ConfigurationManager.AppSettings.Get("DocumentsService")), _DMIdentity); 


    private static IDocumentsService GetDocServiceClient() 
    { 
     ChannelFactory<IDocumentsService> _docSvcFactory = new ChannelFactory<IDocumentsService>(_DMBinding, _DMEndpoint); 

     _docSvcFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust; 

     _docSvcFactory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, ConfigurationManager.AppSettings.Get("ClientCertificate")); 
     _docSvcFactory.Credentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, ConfigurationManager.AppSettings.Get("ServerCertificate")); 


     return _docSvcFactory.CreateChannel(); 
    } 
    #endregion 
} 

한다 : 여기 내 코드의 일부이다

private static Guid _UserID = (HttpContext.Current.User as Titan.Web.Classes.Identity.CustomPrincipal).UserId; 

ServiceObjects.DocumentsSVC.GetDocumentsByFolderID(new DocumentRequest { CurrentUserID = _UserID }) 

_UserID가 채워지는 것을 볼 수는 있지만 서버 쪽에서 볼 수는 없습니다.

<system.serviceModel> 
<bindings> 
    <wsHttpBinding> 
    <binding name="wsHttpEndpointBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="true" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Mtom"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security> 
     <message clientCredentialType="Certificate" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<services> 
    <service name="Titan.WCF.Documents.DocumentsService" behaviorConfiguration="DocumentsServiceBehavior"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="Titan.WCF.Documents.IDocumentsService"> 
     <!-- 
      Upon deployment, the following identity element should be removed or replaced to reflect the 
      identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
      automatically. 
     --> 
     <identity> 
     <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="DocumentsServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <serviceCredentials> 
     <clientCertificate> 
      <!-- Remove the NoCheck in production, this is only for when we use a self signed cert --> 
      <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck" /> 
     </clientCertificate> 
     <serviceCertificate findValue="WCfServer" 
      storeLocation="CurrentUser" 
      storeName="My" 
      x509FindType="FindBySubjectName" /> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
</system.serviceModel> 

답변

0

왜 이렇게 달라질 지 모르지만 그랬습니다.

서비스 참조를 업데이트해야했습니다.

신기한 실수가 있었을 것입니다.하지만 내가 한 유일한 일은 바인딩, 종점 등을 변경하는 것이 었으면 왜 그렇게할까요?

+0

@dhrumilap은 답변에 대한 의견으로 게시하지 않는 한 답장을 통보하지 않습니다. –

0

이 문제가 다음 코드를 사용하여 서비스를 호출 할 방식에있다 보인다 내 서비스의 설정에 : 여기

ServiceObjects.DocumentsSVC.GetDocumentsByFolderID(new DocumentRequest { CurrentUserID = _UserID }); 

당신은 호출하려고 서비스의 프록시 객체를 생성하지 않고 서비스 기능. 그리고 그것은 여러분이 서비스에 정적 클래스를 작성했기 때문입니다.

WCF 서비스에서는 정적 클래스를 사용할 수 없습니다. 클래스 인스턴스 (서비스 프록시 객체)를 작성한 다음 서비스 기능을 호출해야합니다.

+0

안녕하세요 @dhrumilap. 불행히도 그것은지지 않습니다. 나는 지난 2 년 동안 정적 메서드로 코드를 실행 해왔다. 최근에는 보안 요구 사항이 발생하는 베타 사이트에 서비스를 배포하기 위해 보안이 필요한 시점에 이르렀습니다. 내 대답을 확인하십시오. 해결책을 찾았습니다. – Ebbs

+0

@ MrThursday, 내 잘못! – dhrumilap

+0

하하 문제 없어요 :) – Ebbs

1

물론 서비스의 구성을 변경 했으므로 클라이언트가 해당 구성을 측면에서 업데이트 할 수 있도록 서비스 참조를 업데이트해야합니다. 그렇게하지 않는 한 클라이언트는 새로운 구성 설정으로 서비스가 실행되는 동안 구성 파일에서 읽는 이전 구성으로 서비스를 계속 호출합니다.

피곤할 수도 있지만 그것이 그대로입니다.