2011-01-11 8 views
10

मैंने इस त्रुटि के बारे में कुछ घंटे बिताए हैं, और मैंने Google पर लगभग हर चीज का परीक्षण किया है।डब्ल्यूसीएफ मेटाडाटा में एक संदर्भ है जिसे हल नहीं किया जा सकता है

मैं सी # में टीसीपी, .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(); 
    } 
} 

अब मैं ग्राहक बनाना चाहते हैं, लेकिन मैं यह posible नहीं है। मैं सेवा संदर्भ जोड़ें और सीधे 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 सही है। अंतराल द्वारा उपयोग किए जाने वाले व्यवहार, सुरक्षा और बैंड का उपयोग करके बाइंडिंग हैं।

मैंने एक app.config बनाने की कोशिश की है और इसे svcutil.exe के साथ उसी फ़ोल्डर में सेट किया है।

+0

@JohnSaunders, मैं समझ नहीं सकता क्यों अपनी प्रतिष्ठा के साथ किसी प्रश्न कोड में जवाब कोड की नक़ल की है, जिससे पूरी तरह से इस पूरे प्रश्न अमान्य। मैंने प्रश्न कोड और उत्तर कोड के बीच अंतर को हल करने का प्रयास करने में समय बर्बाद कर दिया था इससे पहले कि मुझे एहसास हुआ कि किसी ने जो किया है वह किया है ... ऐसा करने में क्या फायदा है? कोई भी नहीं जानता कि वास्तविक सवाल क्या था। – Sheridan

+0

@Sheridan: यहाँ एक बड़ा जीवन संकेत है: जब भी आप अपने आप को तरह बातें कह पाते हैं, "मैं नहीं समझ सकता कैसे", या "मैं नहीं देख सकते हैं कि", विचार है कि यह अपनी समझ या अपनी दृष्टि का एक मुद्दा हो सकता है । आप "कैसे समझ नहीं सकते" क्योंकि मैंने _do_ नहीं किया था। मैंने अभी कोड को इंडेंट किया है। संपादन इतिहास पर नज़र डालें। मैंने अभी किया। –

+1

मैं * * एक करीबी नजर * पहले * मेरी टिप्पणी की क्या ज़रूरत थी और जब मैं अपनी टिप्पणी स्वीकार करते हैं, मैं कहना है कि यह अभी भी * प्रकट होता है * जैसे कि आप कि कोड जोड़ा चाहते हैं ... आह ... कि बस में है * साइड बाय साइड * व्यू। अन्य विचारों में, मैं सच्ची तस्वीर देख सकता हूं। माफ़ी माँगें ... मुझे टिप्पणी करने से पहले और अधिक बारीकी से देखना चाहिए था। – Sheridan

उत्तर

8

आप इस config आप कोड में आधार का पता परिभाषित करने की जरूरत नहीं होनी चाहिए के साथ सेवा विन्यास

<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 सही ढंग से सेट नहीं कर रहा था। मैंने मेजबान से पहले कोड में बाइंडिंग और व्यवहार घोषित कर दिए हैं। खोलें(); और यह काम किया। – JoanComasFdz

+0

भूल जाते हैं इससे आपकी समस्या का हल कृपया – Shenaniganz

1

मुझे एक ही समस्या थी (जब क्लाइंट ने "सेवा संदर्भ जोड़ें" मेनू में सेवा को "नहीं देखा") केवल टीसीपी बाध्यकारी का उपयोग करते समय। व्यवहार जोड़ने की कोशिश करने के बाद मेरी अपवाद के साथ समाप्त होने की सेवा थी क्योंकि इसे उचित पता नहीं मिला। मुझे नहीं पता कि यह सबसे अच्छा विचार है, लेकिन आप 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 है सेवा संदर्भ जोड़ने के लिए, और स्वचालित रूप से उत्पन्न config net.tcp प्रोटोकॉल का उपयोग करता कॉल करने के लिए समारोह।

+0

एक अच्छा समाधान लगता है यही कारण है, और उसके तर्क लगता है, लेकिन एक बार अपने ग्राहक तैयार की गई है, तो आप http पते की आवश्यकता है जवाब के रूप में चिह्नित करने के लिए नहीं है? – JoanComasFdz

+1

यदि आपके पास एक ग्राहक है तो http पता की आवश्यकता नहीं है। लेकिन अगर आपको भविष्य में कुछ क्लाइंट उत्पन्न करने की आवश्यकता हो सकती है, तो इसे कॉन्फ़िगरेशन में रखना बेहतर है। – 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

मुझे यकीन है कि यह मेरी समस्या है, क्योंकि मैंने कई डेटा अनुबंध बदल दिए हैं। मुझे आश्चर्य है कि आपने उल्लिखित संदेश प्राप्त करने के लिए क्या किया था, संदेश यह पता लगाने में मदद करेगा कि कौन सा डेटा कंट्रैक्ट पहले से मौजूद है –

+0

@HaraldCoppoolse मैंने ब्राउज़र में सेवा देखने का प्रयास किया और वहां एक और विस्तृत त्रुटि दिखाई दी। मैं वीएस 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] तर्क संलग्न, है, तो प्रश्न में त्रुटि दिखाई देगी। पूरी तरह से स्पष्ट नहीं है।

संबंधित मुद्दे