2014-12-24 13 views
0

WCF을 통해 파일을 업로드하는 방법을 설명하고 클라이언트와 서버간에 이 포함 된 클래스를 공유하려고 할 때 몇 가지 문제가있는 다양한 자습서를 따르고 있습니다. 다음과 같이messagecontract로 파일 업로드

기본적으로 내 문제는 다음과 같습니다

나는 별도의 클래스 라이브러리의 내부 RemoteFileInfo MessageContract 클래스가 :

[MessageContract] 
public class RemoteFileInfo : IDisposable 
{ 

    private System.IO.Stream fileByteStream; 

    [MessageBodyMember(Order = 1)] 
    public System.IO.Stream FileByteStream 
    { 
     set { this.fileByteStream = value; } 
     get { return this.fileByteStream; } 
    } 

    /*More properties here declared as regular properties or [MessageHeader]*/ 
} 

그때 서버와 클라이언트 모두에 해당 라이브러리를 공유 할 수 있습니다. 이는 클라이언트 이 자신의 RemoteFileInfo 클래스를 구현하지 않아야 함을 의미합니다. 그러나 클라이언트 프로젝트에 .dll을 추가 한 다음 Reuse Types을 사용하여 Add Service Reference을 사용하면 서비스 참조의 네임 스페이스 내부에 RemoteFileInfo 클래스가 다시 만들어져 원래 클래스 라이브러리의 형식과 그 사이에 모호성이 생깁니다.

내 질문은 클라이언트와 서버간에 MessageContract으로 선언 된 클래스를 어떻게 공유 할 수 있습니까? OperationContractRemoteFileInfo 개체가 필요하고 원래 RemoteFileInfo 클래스에서 선언 한 동일한 속성을 유지하고 싶기 때문에이 작업을 수행해야합니다. 내 OperationContract

는 :

[OperationContract] 
    void uploadFile(RemoteFileInfo request); 

나는이 서비스 계약에 선언하는 방법을 정확히 클라이언트 에서 해당 메소드를 호출 할 수 있어야합니다. 지금까지 서비스 참조를 추가 할 때 Generate message headers 옵션을 사용하여 주위를 둘러 보았을 때 스트림 대신 byte[] 매개 변수가있는 uploadFile 메서드로 끝나고 스트림이되어야합니다.

아이디어가 있으십니까?

편집 : 클라이언트 구성을 게시 할 예정 이었지만 기존의 app.config가 없으므로 Windows 스토어 응용 프로그램 용으로 개발 중이라고 언급해야합니다.

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IRTMobileWebService" sendTimeout="00:05:00" /> 
     </basicHttpBinding> 
     <netTcpBinding> 
     <binding name="uploadEndpoint" sendTimeout="00:05:00" transferMode="Streamed"> 
      <security mode="None" /> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://ipaddress/RTWebServices/RTMobileWebService.svc/basic" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRTMobileWebService" 
      contract="IRTMobileWebService" name="BasicHttpBinding_IRTMobileWebService" /> 
     <endpoint address="net.tcp://ipaddress/RTWebServices/RTMobileWebService.svc/upload" 
      binding="netTcpBinding" bindingConfiguration="uploadEndpoint" 
      contract="IRTMobileImageService" name="uploadEndpoint"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 

가 어떻게 더의 app.config과 윈도우 스토어 앱에서이를 복제 할 다음 WCF 테스트 클라이언트가 어쨌든 클라이언트 설정에 대해 생성 무엇을 Heres

?

답변

0

이미 서비스 인터페이스가있는 dll을 공유하는 경우 마법사를 사용하여 서비스 참조를 추가하지 않아도됩니다. 시간의 상당 부분을 놓치고 많은 경우에 서비스 인터페이스의 완전히 새로운 인스턴스를 포함하여 필요한 것보다 훨씬 많은 코드가 필요합니다.

class ClientServiceClass : ClientBase<ITheServiceContract>, ITheServiceContract 
{ 

    public ClientServiceClass (string endpointConfigurationName) : 
     base(endpointConfigurationName) 
    { 
    } 

    internal void uploadFile(RemoteFileInfo request) 
    { 
     Channel.uploadFile(request); 
    } 
} 
ITheServiceContract는 서비스 계약입니다 공유 DLL에서 인터페이스입니다

ClientServiceClass은 다음과 같습니다

대신, 서비스를 소비하는 응용 프로그램에서이 같은 서비스에 대한 자신의 프록시 클래스를 생성 서비스 프록시 클래스의 구현을 호출하려는 모든 것 (마법사는 일반적으로 서비스 이름으로이를 호출합니다).때 그 실행

은 "endpointNameFromAppConfig"
NetTcpBinding binding = new NetTcpBinding(); 
binding.TransferMode = TransferMode.Streamed; 
binding.Security = new NetTcpSecurity(); 
binding.Security.Mode = SecurityMode.None; 
EndpointAddress address = new EndpointAddress("net.tcp://serviceEndpointAddress"); 
ClientServiceClass uploadClient = new ClientServiceClass(binding, address); 
uploadClient.Open(); 
uploadClient.uploadFile(yourFileInfoRequest); 
uploadClient.Close(); 
+0

내가 WCFTest 클라이언트에서 클라이언트 설정을 복사하여 얻을 수있는 엔드 포인트의 이름입니다

은 다음과 같이 그것을 코드에서 서비스를 사용하려면 Visual Studio에서 서비스를 실행하십시오. – user1806716

+0

예. 대답을 더 완전하게 만들기 위해 예제 클라이언트 구성을 잠시 추가 할 것입니다. – dodexahedron

+0

nettcpbinding에 관한 새로운 오류와 함께 구성을 게시합니다. – user1806716