2011-01-11 3 views
10

나는이 오류에 대해 몇 시간 동안 검색 한 결과 Google에있는 모든 것을 거의 테스트했습니다.WCF 메타 데이터에는 해결할 수없는 참조가 포함되어 있습니다.

C#에서 TCP, .NET4 및 VS2010을 사용하여 서비스에 액세스하려고합니다.


namespace WcfService_using_callbacks_via_tcp 
{ 
    [ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] 
    public interface IService1 
    { 
     [OperationContract] 
     string Test(int value); 
    } 

    public interface ICallback 
    { 
     [OperationContract(IsOneWay = true)] 
     void ServerToClient(string sms); 
    } 
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] 
    public class Service1 : IService1 
    { 
     public string Test(int value) 
     { 
      ICallback the_callback = OperationContext.Current.GetCallbackChannel<ICallback>(); 
      the_callback.ServerToClient("Callback from server, waiting 1s to return value."); 
      Thread.Sleep(1000); 
      return string.Format("You entered: {0}", value); 
     } 

    } 
} 

이의 Web.config와 :


<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="WcfService_using_callbacks_via_tcp.Service1" behaviorConfiguration="Behaviour_Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:5050/Service1" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="DuplexNetTcpBinding_IService1" contract="WcfService_using_callbacks_via_tcp.IService1"/> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="mexTcp" contract="IMetadataExchange"/> 
     </service> 
    </services> 

    <bindings> 
     <!-- 
     TCP Binding 
     --> 
     <netTcpBinding> 
     <binding name="DuplexNetTcpBinding_IService1" sendTimeout="00:00:01" 
       portSharingEnabled="true"> 

     </binding> 

     <binding name="mexTcp" portSharingEnabled="true"> 
      <security mode="None" /> 
     </binding> 
     </netTcpBinding> 


    </bindings> 

    <behaviors> 
     <serviceBehaviors> 
     <!-- 
      Behaviour to avoid a rush of clients and to expose metadata over tcp 
     --> 
     <behavior name="Behaviour_Service1"> 
      <serviceThrottling maxConcurrentSessions="10000"/> 
      <serviceMetadata httpGetEnabled="true"/> 
     </behavior> 

     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

그리고 생

나는 아주 작은 서비스를


static void Main(string[] args) 
{ 
    Uri base_address = new Uri("net.tcp://localhost:5050/Service1"); 
    ServiceHost host = null; 
    try 
    { 
     // Create the server 
     host = new ServiceHost(typeof(Service1), base_address); 
     // Start the server 
     host.Open(); 
     // Notify it 
     Console.WriteLine("The service is ready at {0}", base_address); 
     // Allow close the server 
     Console.WriteLine("Press <Enter> to stop the service."); 
     Console.ReadLine(); 
     // Close it 
     host.Close(); 
    } 
    catch (Exception ex) 
    { 
     // Opus an error occurred 
     Console.ForegroundColor = ConsoleColor.Red; 
     Console.WriteLine(string.Format("Host error:\r\n{0}:\r\n{1}", ex.GetType(), ex.Message)); 
     Console.ReadLine(); 
    }finally 
    { 
     // Correct memory clean 
     if(host != null) 
      ((IDisposable)host).Dispose(); 
    } 
} 

가 지금은 클라이언트를 만들려면,하지만 난 그것을 추적 할 수없는 가망되지 않습니다 :의 코드는 호스트합니다. 나는 서비스 참조를 추가하고 직접적으로는 svcutil 사용했지만,이 오류를 받고 있어요 :


C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>svcutil.exe net.tcp://loc alhost:5050/Service1 Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1] Copyright (c) Microsoft Corporation. All rights reserved.

Attempting to download metadata from 'net.tcp://localhost:5050/Service1' using W S-Metadata Exchange. This URL does not support DISCO. Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1] Copyright (c) Microsoft Corporation. All rights reserved.

Error: Cannot obtain Metadata from net.tcp://localhost:5050/Service1

If this is a Windows (R) Communication Foundation service to which you have acce ss, please check that you have enabled metadata publishing at the specified addr ess. For help enabling metadata publishing, please refer to the MSDN documentat ion at http://go.microsoft.com/fwlink/?LinkId=65455 .

WS-Metadata Exchange Error URI: net.tcp://localhost:5050/Service1

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost: 5050/Service1'.

The socket connection was aborted. This could be caused by an error processi ng your message or a receive timeout being exceeded by the remote host, or an un derlying network resource issue. Local socket timeout was '00:04:59.9863281'.

Se ha forzado la interrupción de una conexión existente por el host remoto

If you would like more help, type "svcutil /?"


그래서, 문제없이 서비스를 호스팅 할 수 있지만 프록시를 만들 수 없습니다.

내가 찾은 거의 모든 설정을 시도했지만 현재 web.config가 올바른 것 같습니다. 엔드 포인트에서 사용되는 mex를 사용하는 동작, 보안 및 바인딩이 있습니다.

app.config를 만들고 svcutil.exe를 사용하여 같은 폴더로 설정하려고했습니다.

+0

@ JohnSaunders, 나는 평판이있는 누군가가 응답 코드를 질문 코드에 복사하여이 전체 질문을 완전히 무효화하는 이유를 이해할 수 없습니다. 나는 누군가가 당신이 한 일을했다는 것을 깨닫기 전에 질문 코드와 응답 코드의 차이점을 찾기 위해 시간을 낭비했다. 아무도 실제 질문이 무엇인지 알 수 없었습니다. – Sheridan

+0

@Sheridan : 여기에 큰 힌트가 있습니다. "어떻게 이해할 수 없는가", 또는 "어떻게 볼 수 없는가"와 같은 말을 발견 할 때마다 그것이 당신의 이해 또는 비전의 문제 일 수 있다고 생각하십시오. . 내가 어떻게하지 않았기 때문에 당신은 "어떻게 이해할 수 없다". 방금 코드를 들여 썼습니다. 편집 내역을 자세히 살펴보십시오. 난 그냥했다. –

+1

* * * 내 의견을보기 전에 * 가까이에 * 보았습니다. 귀하의 의견을 수락하는 동안 나는 그 코드를 추가 한 것처럼 * 여전히 * 나타납니다. 아아 ... 그냥 * Side by Side *보기. 다른 견해들에서 나는 진실 된 그림을 볼 수있다. 죄송합니다 ... 나는 논평하기 전에 좀 더 자세히보아야했습니다. – Sheridan

답변

8

당신은 당신이 코드에서 기본 주소를 정의 할 필요가 없습니다이 설정을 통해 서비스 구성

<system.serviceModel> 
    <services> 
    <service name="WcfService_using_callbacks_via_tcp.Service1" 
     behaviorConfiguration="Behavior_Service1"> 
     <host> 
     <baseAddresses> 
      <add baseAddress="net.tcp://localhost:5050/Service1" /> 
     </baseAddresses> 
     </host> 
     <endpoint address="" contract="WcfService_using_callbacks_via_tcp.IService1" 
     binding="netTcpBinding" bindingConfiguration="DuplexNetTcpBinding_IService1" /> 
     <endpoint address="mex" contract="IMetadataExchange" binding="mexTcpBindng" /> 
    </service> 
    </services> 
    ... 
</system.serviceModel> 

가 누락되었습니다.

+0

답장을 보내 주셔서 감사합니다. 내 서버의 콘솔 프로젝트에서 app.config를 올바르게 설정하지 않았습니다. host.Open(); 전에 코드에서 바인딩 및 비헤이비어를 선언했습니다. 그리고 효과가있었습니다. – JoanComasFdz

+0

이것이 문제를 해결했다면 답을 표시하는 것을 잊지 마세요. – Shenaniganz

1

tcp 바인딩 만 사용하는 동안 클라이언트가 "서비스 참조 추가"메뉴에서 서비스를 "보지 못했을 때"동일한 문제가 발생했습니다. Behavior를 추가하려고 시도한 후 적절한 주소를 찾지 못했기 때문에 서비스를 예외로 종료했습니다. 좋은 생각인지 모르겠지만 http로 두 번째 기본 주소를 추가 할 수 있습니다 .... 여기 내 설정 및 코드, 작동합니다.

<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <services> 
    <service name="TestBindings.StockQuoteService"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="net.tcp://10.62.60.62:34000/StockQuoteService" /> 
     <add baseAddress ="http://10.62.60.62:12000/StockQuoteService"/> 
     </baseAddresses> 
    </host> 
    <endpoint address="" 
    contract="TestBindings.IStockQuoteService" 
    binding="netTcpBinding" /> 
    </service> 
</services> 

하고 HTTP 주소는 이제 클라이언트 측에서 설정을 서비스 참조를 추가 할 클라이언트 usend, 자동으로 생성되는

class Program 
{ 
    static void Main(string[] args) 
    { 
     ServiceHost sh = new ServiceHost(typeof(StockQuoteService)); 
     ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); 
     behavior.HttpGetEnabled = true; 
     sh.Description.Behaviors.Add(behavior); 
     sh.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), 
      "mex"); 
     sh.Open(); 

코드는 전화를 net.tcp 프로토콜을 사용하여 기능.

+0

멋진 솔루션 인 것처럼 보입니다.하지만 클라이언트가 생성되면 http 주소가 필요합니까? – JoanComasFdz

+1

하나의 클라이언트가있는 경우 http 주소가 필요하지 않습니다. 그러나 향후에 일부 클라이언트를 생성해야하는 경우 config로 설정하는 것이 좋습니다. – Anna

2

내가 같은 오류 메시지가 표시되고 그것을 알고 보니, 문제가 주석이 주석 블록에서 같은 문자를 제거한 후

<!-- comments included characters like à, ç and ã --> 

을 차단 내에서 텍스트 예정이었다, 모든 작동

3

기존 서비스 참조를 업데이트하는 동안 동일한 오류가 발생했습니다. 동일한 네임 스페이스 내에서 동일한 이름의 데이터 계약이 있음이 밝혀졌습니다. 추가 조사를 통해 실제 오류가 발생했습니다 :

DataContract for type [redacted] cannot be added to DataContractSet since type '[redacted]' with the same data contract name 'DocumentInfo' in namespace '[redacted]' is already present and the contracts are not equivalent.

변경 사항 중 하나에 대해 이름을 제공하기 위해 DataContract가 변경되었습니다.

[DataContract(Namespace = "urn:*[redacted]*:DataContracts", Name = "SC_DocumentInfo")] 

같은 문제가있는 사람에게 도움이 될 수 있도록 여기에 게시하고 있습니다.

+0

몇 가지 데이터 계약을 변경했기 때문에 이것이 내 문제라고 확신합니다. 당신이 언급 한 메시지를 얻기 위해 무엇을했는지 궁금합니다. 메시지는 이미 존재하는 DataContract를 찾는 데 도움이됩니다. –

+0

@HaraldCoppoolse 브라우저에서 서비스를 보려고 시도했는데 더 자세한 오류가 나타났습니다. 저는 VS 2015를 사용하고 있습니다. 서비스로 이동하여 마우스 오른쪽 버튼을 클릭하고 브라우저에서보기를 선택했습니다. 나는 너를 돕기를 바란다. – mslissap

1

아마도 누군가에게 도움이 될 것입니다.

내 문제는 계약 인수에 있었다, 나는 이벤트 뷰어의 도움으로 그것을 발견 : 당신이 이미 가지고 [MessageContract] 인수를 하나 개 이상의 인수를 추가하는 경우,

The operation [Name of method] either has a parameter or a return type that is attributed with MessageContractAttribute. In order to represent the request message using a Message Contract, the operation must have a single parameter attributed with MessageContractAttribute. In order to represent the response message using a Message Contract, the operation's return value must be a type that is attributed with MessageContractAttribute and the operation may not have any out or ref parameters.

당신도 다음 문제의 오류를 보게됩니다. 완전히 명확하지 않습니다.

관련 문제