문제

나는 설정의 WCF 웹 서비스에 연결하는 동적으로 데스크톱 응용 프로그램입니다.

내 문제입니다 정말 대한 자세한 설정하는 WCF 이 필요합니다.을 받고 SSL 작업을 포함한 사용자 정의 설정입니다.을 받고딩을 지정합 또는 다른 것을 작품에서는 더 많은 것이 필요합니다.당신이 원하는 압축?여기서 우리는 다시 갈...

WCF 은 정말 강력한다-당신의 호스트를 사용할 수 있습니다 다른 방법으로 연결지만,모든 것을의 많은 참여 자세한 config.는 경우스 및 클라이언트와 일치하지 않는 완벽하게 당신이 힘들고 해독하는 오류가 있습니다.

을 만들고 싶 데스크탑 앱을 훨씬 쉽게 구성-이상적으로 어떤 종류의 자동 발견이 있습니다.사용자의 데스크탑 앱을 할 수 있어야하고 URL 을 입력하고 그것은 나머지를 할 수 있습니다.

누군가 알고있는 좋은 방법이 있을까요?

나는 알고 Visual Studio 를 설정할 수 있습니다 config,당신을 위해 하지만 나는 원하지할 수 있도록 응용 프로그램을 기반으로 그것을 다양한 다른 서버 설정을 용이하게 합니다.

내가 알고 있는 대의 도구를 사용할 수 있습니다.,외부에서 그러나 내가 찾는 사용자의 데스크탑 앱을 유지하고 있다 WCF 갖습니다.알 MS 만들어 이를 통해 의도적으로 복잡합니다.

어떤 방법,기계장치,제 3 자 라이브러리는 아무것도 만들의 자동 검색 WCF 설정이 가능한가요?

도움이 되었습니까?

해결책

에 대한 모든 정보를 끝점에서 사용할 수 있는 메타데이터의 서비스를 작성할 수 있습니다 클라이언트 무엇을 할 것을 탐구한 메타 데이터의 서비스와 구성됩니다.에 대한 코드를 들어 볼 수 있으로 이수한 Mex Explorer 에서 유발 Lowy.

다른 팁

감사,는 유용한 코드(+1)입니다.

그것보다 더 조금 지저분하지만,일부 버그(경우에 민감한 검사를 해서는 안됩,예를 들어),부하의 UI 는 기능이 필요 없고 반복의 많은 코드입니다.

나가서 찍은 실제적인 메커니즘을 다시는 그것을 썼다고 거의 가지고 작업(연결지만,필요정하느라 하세월).

처음부 링커 특유의 옵션을 추가 기능을 사용하는 주요 방법:

/// <summary>If the url doesn't end with a WSDL query string append it</summary>
static string AddWsdlQueryStringIfMissing( string input )
{
    return input.EndsWith( "?wsdl", StringComparison.OrdinalIgnoreCase ) ?
        input : input + "?wsdl";
}

/// <summary>Imports the meta data from the specified location</summary>
static ServiceEndpointCollection GetEndpoints( BindingElement bindingElement, Uri address, MetadataExchangeClientMode mode )
{
    CustomBinding binding = new CustomBinding( bindingElement );
    MetadataSet metadata = new MetadataExchangeClient( binding ).GetMetadata( address, mode );
    return new WsdlImporter( metadata ).ImportAllEndpoints();
}

다음 방법도 다른 방법 연결하고 반환합니다 끝점:

public static ServiceEndpointCollection Discover( string url )
{
    Uri address = new Uri( url );
    ServiceEndpointCollection endpoints = null;

    if ( string.Equals( address.Scheme, "http", StringComparison.OrdinalIgnoreCase ) )
    {
        var httpBindingElement = new HttpTransportBindingElement();

        //Try the HTTP MEX Endpoint
        try { endpoints = GetEndpoints( httpBindingElement, address, MetadataExchangeClientMode.MetadataExchange ); }
        catch { }

        //Try over HTTP-GET
        if ( endpoints == null )
            endpoints = GetEndpoints( httpBindingElement,
                new Uri( AddWsdlQueryStringIfMissing( url ) ), MetadataExchangeClientMode.HttpGet );
    }
    else if ( string.Equals( address.Scheme, "https", StringComparison.OrdinalIgnoreCase ) )
    {
        var httpsBindingElement = new HttpsTransportBindingElement();

        //Try the HTTPS MEX Endpoint
        try { endpoints = GetEndpoints( httpsBindingElement, address, MetadataExchangeClientMode.MetadataExchange ); }
        catch { }

        //Try over HTTP-GET
        if ( endpoints == null )
            endpoints = GetEndpoints( httpsBindingElement,
                new Uri( AddWsdlQueryStringIfMissing( url ) ), MetadataExchangeClientMode.HttpGet );
    }
    else if ( string.Equals( address.Scheme, "net.tcp", StringComparison.OrdinalIgnoreCase ) )
        endpoints = GetEndpoints( new TcpTransportBindingElement(), 
            address, MetadataExchangeClientMode.MetadataExchange );

    else if ( string.Equals( address.Scheme, "net.pipe", StringComparison.OrdinalIgnoreCase ) )
        endpoints = GetEndpoints( new NamedPipeTransportBindingElement(), 
            address, MetadataExchangeClientMode.MetadataExchange );

    return endpoints;
}

이제 또 다른 방법이 사용할 수 없을 때 나는 원래 질문입니다.Microsoft 지원을 위한 나머지 WCF 서비스입니다.

  • 의 단점을 사용하여 나머지 부분은 당신을 잃 WSDL.
  • 거꾸로 최소한의 구성 및 WCF 인터페이스 계약 여전히 작동할 것입니다!

해야 합 새로운 참조 System.ServiceModel.Web

표시 작업을 중 WebInvokeWebGet

//get a user - note that this can be cached by IIS and proxies
[WebGet]
User GetUser(string id )

//post changes to a user
[WebInvoke]
void SaveUser(string id, User changes )

이러한 추가 사이트를 쉽게 추가 .svc 파일:

<%@ServiceHost 
   Service="MyNamespace.MyServiceImplementationClass" 
   Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

공장 라인에게 말 ASP.net 을 활성화하는 방법 endpoint-당신은 필요 없는 서버측 구성에서 모두!

다음을 건설 ChannelFactory 은 거의 변경되지 않은 것을 제외하고,당신이 필요하지 않 끝점을 지정하는 어떤 이상(또는 자동차-발견 중 하나로 나이에 다른 답변)

var cf = new WebChannelFactory<IMyContractInterface>();
var binding = new WebHttpBinding();

cf.Endpoint.Binding = binding;
cf.Endpoint.Address = new EndpointAddress(new Uri("mywebsite.com/myservice.svc"));
cf.Endpoint.Behaviors.Add(new WebHttpBehavior());

IMyContractInterface wcfClient = cf.CreateChannel();

var usr = wcfClient.GetUser("demouser");
// and so on...

참고 하지는 않았 지정 또는 발견되는 클라이언트 구성의 현지 구성이 필요!

다른 큰 거꾸로 쉽게 전환할 수 있습니다 JSON 바코드 표시할 수 있도록 동일한 WCF 서비스에서 사용하 Java,ActionScript,Javascript,Silverlight 또는 다른 처리할 수 있는 JSON 및 나머지 쉽습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top