2011-01-11 145 views
10

私はこのエラーについて検索するのに数時間を費やしました。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> 

そしてチ

私は非常に小さなサービスを持っていますsのそれをホストするためのコード:


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

私はあなたのコメントを受け入れる間に、あなたがそのコードを追加したように*まだ*表示されていると言いたいと思います。ああ、サイドバイサイド*ビュー。他のビューでは、私は本当の絵を見ることができます。謝罪...私はコメントする前にもっと詳しく調べておくべきだった。 – 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

私は同じ問題を抱えていました(クライアントが「サービス参照の追加」メニューでサービスを「見ない」とき)。 Behaviorを追加しようとした後、適切なアドレスが見つからなかったため、私のサービスは例外で終了しました。 ベストアイデアかどうか分かりませんが、2番目のベースアドレスを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> 

とコード

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(); 

httpアドレスは、現在サービス参照を追加するために、クライアントによってUSEND、およびクライアント側で自動的に生成された設定を呼び出すためにnet.tcpプロトコルを使用しています関数。

+0

それは素敵なソリューションと思われますが、一見あなたのクライアントが生成されたら、httpアドレスが必要ですか? – JoanComasFdz

+1

クライアントが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.

私は、クラスの1つに名前を付けるようにDataContractを変更しました。

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

同じ問題を抱えている人を助けるかもしれないので、私はここに掲載しています。

+0

私はいくつかのデータ契約を変更したので、これが私の問題だと確信しています。私はあなたが上記のメッセージを得るために何をしたのだろうか?そのメッセージは、どのDataContractがすでに存在しているかを知るのに役立つでしょう。 –

+0

@HaraldCoppoolseブラウザでサービスを表示しようとしました。私は、VS 2015を使用して、サービスにナビゲートし、右クリックしてブラウザーで選択しました。私はあなたを助けることを願っています – mslissap

1

多分それは誰かにとって役に立ちます。

私の問題は、契約の引数にあった、と私はイベントビューアの助けを借りて、それを発見しました:だから

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.

、あなたはすでにあなたがして、[MessageContract]引数を持つ、複数の引数を付加した場合問題のエラーが表示されます。完全にはっきりしない。

関連する問題