لا يمكن العثور على عنصر نقطة النهاية الافتراضية

StackOverflow https://stackoverflow.com/questions/352654

سؤال

لقد أضفت وكيلًا إلى خدمة ويب إلى حل VS2008/.NET 3.5. عند بناء العميل .NET يلقي هذا الخطأ:

لا يمكن العثور على عنصر نقطة النهاية الافتراضية الذي يشير إلى تعاقد "imysoapwebwebservice" في قسم تكوين عميل ServiceModel. قد يكون هذا لأنه لم يتم العثور على ملف تكوين للتطبيق الخاص بك أو لأنه لا يمكن العثور على عنصر نقطة نهاية مطابقة لهذا العقد في عنصر العميل.

يطلب مني البحث عن هذا الخطأ استخدام مساحة الاسم الكاملة في العقد. ها هو app.config مع مساحة الاسم الكاملة:

<client>
  <endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
            binding="basicHttpBinding" bindingConfiguration="IMySOAPWebServicebinding"
            contract="Fusion.DataExchange.Workflows.IMySOAPWebService" name="IMySOAPWebServicePort" />
</client>

أقوم بتشغيل XP Local (أذكر هذا لأن عددًا من أغاني Google ذكر Win2K3) يتم نسخ App.Config إلى App.exe.config ، بحيث لا تكون هذه هي المشكلة أيضًا.

أي أدلة؟

هل كانت مفيدة؟

المحلول 3

بعد اختبار العديد من الخيارات ، حللت ذلك أخيرًا باستخدام

العقد = "imysoapwebservice"

أي بدون مساحة الاسم الكاملة في التكوين. لسبب ما ، لم يحل الاسم الكامل بشكل صحيح

نصائح أخرى

"يمكن أن ينشأ هذا الخطأ إذا كنت تتصل بالخدمة في مكتبة الفصل والاتصال بمكتبة الفصل من مشروع آخر."

في هذه الحالة ، ستحتاج إلى تضمين إعدادات تكوين WS في app.config للمشاريع الرئيسية إذا كان winapp أو web.config إذا كان تطبيق ويب. هذه هي الطريقة للذهاب حتى مع Prism و WPF/Silverlight.

لقد قمت بحل هذا (أعتقد أنه كما قد اقترح الآخرون) من خلال إنشاء مثيلات عنوان الربط والنقطة النهائية بنفسي - لأنني لم أكن أرغب في إضافة إعدادات جديدة إلى ملفات التكوين (هذا بديل لبعض رمز المكتبة الحالي الذي يتم استخدامه على نطاق واسع ، واستخدمت سابقًا مرجع خدمة ويب أقدم وما إلى ذلك) ، ولذا أردت أن أتمكن من إسقاط هذا دون إضافة إعدادات تكوين جديدة في كل مكان.

var remoteAddress = new System.ServiceModel.EndpointAddress(_webServiceUrl);

using (var productService = new ProductClient(new System.ServiceModel.BasicHttpBinding(), remoteAddress))
{
    //set timeout
    productService.Endpoint.Binding.SendTimeout = new TimeSpan(0,0,0,_webServiceTimeout);

    //call web service method
    productResponse = productService.GetProducts();
} 

يحرر

إذا كنت تستخدم HTTPS ، فأنت بحاجة إلى استخدام BasicHttpsBinding عوضا عن BasicHttpBinding.

لقد واجهت نفس القضية. اتضح أنه بالنسبة لمرجع ويب ، يجب عليك تزويد عنوان URL كمعلمة أول إلى المُنشئ:

new WebService.WebServiceSoapClient("http://myservice.com/moo.aspx");

للحصول على مرجع جديد لخدمة الويب ، يجب عليك توفير اسم يشير إلى إدخال نقطة النهاية في التكوين:

new WebService.WebServiceSoapClient("WebServiceEndpoint");

مع إدخال مقابل في Web.config أو App.config:

<client>
      <endpoint address="http://myservice.com/moo.aspx"
        binding="basicHttpBinding" 
        bindingConfiguration="WebService"
        contract="WebService.WebServiceSoap"
        name="WebServiceEndpoint" />
    </client>
  </system.serviceModel>

من الصعب للغاية إزالة رؤية النفق على "لقد عملت في برنامج أقدم" ...

كان لدي موقف مثل هذا ، حيث كان لدي

  • استضافت خدمة WCF في مكان ما
  • المشروع الرئيسي
  • مشروع المستهلك من النوع "مكتبة الفصل" الذي لديه مرجع الخدمة إلى خدمة WCF
  • أساليب استدعاء المشروع الرئيسية من مشروع المستهلك

الآن كان لدى مشروع المستهلك جميع إعدادات التكوين ذات الصلة في <system.serviceModel> علامة App.Config ، كان لا يزال يرمي نفس الخطأ كما ورد أعلاه.

كل ما فعلته هو إضافة نفس العلامة <system.serviceModel> إلى ملف App.Config الخاص بمشروعي الرئيسي ، وأخيراً كنا على ما يرام.

المشكلة الحقيقية ، بقدر ما كانت في حالتي ، كانت تقرأ ملف التكوين الخاطئ. بدلاً من App.Config للمستهلك ، كان يشير إلى تكوين Proj الرئيسي. استغرق الأمر مني ساعتين لمعرفة ذلك.

"يمكن أن ينشأ هذا الخطأ إذا كنت تتصل بالخدمة في مكتبة الفصل والاتصال بمكتبة الفصل من مشروع آخر."

"في هذه الحالة ، ستحتاج إلى تضمين إعدادات تكوين WS في تطبيق المشاريع الرئيسية.

نعم ، ولكن إذا لم تتمكن من تغيير المشروع الرئيسي (Orchard CMS على سبيل المثال) ، يمكنك الاحتفاظ بتكوين خدمة WCF في مشروعك.

تحتاج إلى إنشاء مساعد خدمة مع طريقة توليد العميل:

public static class ServiceClientHelper
{
    public static T GetClient<T>(string moduleName) where T : IClientChannel
    {
        var channelType = typeof(T);
        var contractType = channelType.GetInterfaces().First(i => i.Namespace == channelType.Namespace);
        var contractAttribute = contractType.GetCustomAttributes(typeof(ServiceContractAttribute), false).First() as ServiceContractAttribute;

        if (contractAttribute == null)
            throw new Exception("contractAttribute not configured");

        //path to your lib app.config (mark as "Copy Always" in properties)
        var configPath = HostingEnvironment.MapPath(String.Format("~/Modules/{0}/bin/{0}.dll.config", moduleName)); 

        var configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = configPath }, ConfigurationUserLevel.None);
        var serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);

        if (serviceModelSectionGroup == null)
            throw new Exception("serviceModelSectionGroup not configured");

        var endpoint = serviceModelSectionGroup.Client.Endpoints.OfType<ChannelEndpointElement>().First(e => e.Contract == contractAttribute.ConfigurationName);
        var channelFactory = new ConfigurationChannelFactory<T>(endpoint.Name, configuration, null);
        var client = channelFactory.CreateChannel();
        return client;
    }
}

واستخدامه:

using (var client = ServiceClientHelper.GetClient<IDefaultNameServiceChannel>(yourLibName)) {
                ... get data from service ...
            }

انظر التفاصيل في هذه المقالة.

هذا واحد دفعني إلى الجنون.

أنا أستخدم Silverlight 3 Prism (CAB) مع WCF

عندما أتصل بخدمة WCF في وحدة PRISM ، أحصل على نفس الخطأ:

لا يمكن العثور على عنصر نقطة النهاية الافتراضية الذي يشير إلى عقد "ImyService" في قسم تكوين عميل نموذج الخدمة. قد يكون هذا لأنه لم يتم العثور على ملف تكوين للتطبيق الخاص بك أو لأنه لا يمكن العثور على عنصر نقطة نهاية مطابقة لهذا العقد في عنصر العميل

اتضح أن النظر في ملف .xap الخاص بـ shell لملف servicereferences.clientConfig ، وليس في ملف servicereferences.clientConfig للوحدة. لقد أضفت نقطة النهاية الخاصة بي وربط ملف servicereferences.

ثم اضطررت إلى إعادة بناء تطبيق Shell لإنشاء ملف .xap الجديد لمجلد عميل مشروع الويب الخاص بي.

الآن يعمل هذا السطر من الكود أخيرًا:

MyServiceClient myService = new MyServiceClient();

تضغط العديد من الردود هنا على الحل الصحيح عندما تواجه الخطأ الغامض للعقل المتمثل في الرجوع إلى الخدمة من ملف فئة: انسخ معلومات تكوين الخدمة في app.config web.config من وحدة التحكم أو تطبيق Windows. لا يبدو أن أيا من هذه الإجابات تظهر لك ما يجب نسخه. دعنا نحاول تصحيح ذلك.

إليك ما قمت بنسخه من ملف التكوين الخاص بمكتبة الفصول الدراسية ، في ملف التكوين الخاص بتطبيق وحدة التحكم ، من أجل الالتفاف على هذا الخطأ المجنون لخدمة تكتب تسمى "TranslationServiceOutBound".

تريد أساسا كل شيء داخل System.ServicEmodel الجزء:

  <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ITranslationServiceOutbound" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://MyHostName/TranslationServiceOutbound/TranslationServiceOutbound.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITranslationServiceOutbound"
    contract="TranslationService.ITranslationServiceOutbound" name="BasicHttpBinding_ITranslationServiceOutbound" />
</client>

كنت أحصل على هذا الخطأ ضمن تطبيق ASP.NET حيث تمت إضافة خدمة WCF إلى مكتبة الفصل التي تتم إضافتها إلى تطبيق ASP.NET كملف .dll مشار إليه في مجلد BIN. لحل الخطأ ، يجب نسخ إعدادات التكوين في ملف app.config ضمن مكتبة الفئة التي تشير إلى خدمة WCF في إعدادات web.config لموقع/تطبيق ASP.NET.

لقد وجدت (بالإضافة إلى النسخ إلى App.Config الخاص بـ Client UI حيث كنت أستخدم واجهة مكتبة الفصل) كان عليّ أن أقوم ببادئة اسم الربط باسم مرجع الخدمة (Mine IS ServiceReference في أدناه).

على سبيل المثال:

<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_ISchedulerService"
      contract="ServiceReference.ISchedulerService" 
      name="BasicHttpBinding_ISchedulerService" />

بدلا من الافتراضي المتولد:

<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_ISchedulerService"
      contract="ISchedulerService" 
      name="BasicHttpBinding_ISchedulerService" />

واجهت نفس المشكلة ، لكن تغيير مساحة اسم العقد لم ينجح بالنسبة لي. لذلك جربت مرجع الويب .NET 2 Style بدلاً من مرجع خدمة .NET 3.5. هذا مشغول.

لاستخدام مرجع ويب في Visual Studio 2008 ، انقر فوق "إضافة مرجع الخدمة" ، ثم انقر فوق "متقدم" عندما يظهر مربع الحوار. في ذلك ، ستجد خيارًا يتيح لك استخدام مرجع ويب بدلاً من مرجع الخدمة.

لا يمكن أن يسبب اختبار الوحدة تطبيقًا غير مكتبة يستهلك الخدمة هذه المشكلة.

المعلومات التي أدخلها الآخرون معالجة السبب الجذري لهذا. إذا كنت تحاول كتابة حالات الاختبار الآلية والوحدة التي تختبرها ستستدعي بالفعل واجهة الخدمة ، فأنت بحاجة إلى إضافة مرجع الخدمة إلى مشروع الاختبار. هذه نكهة التطبيق باستخدام نوع الخطأ المكتبة. لم أدرك هذا على الفور لأن الكود الخاص بي الذي يستهلك الواجهة ليس في مكتبة. ومع ذلك ، عندما يتم تشغيل الاختبار فعليًا ، سيتم تشغيله من مجموعة الاختبار ، وليس التجميع قيد الاختبار.

إضافة مرجع الخدمة إلى مشروع اختبار الوحدة حل مشكلتي.

لدي موقف في اختبار الوحدة. قمت بنسخ ملف App.Config إلى مشروع اختبار الوحدة. لذلك يحتوي مشروع اختبار الوحدة أيضًا على معلومات نقطة النهاية.

واجهت هذه المشكلة مرة واحدة. كان ذلك لأنني كنت لا أزال أقوم بتطوير الواجهة التي تستخدم خدمة WCF. لقد قمت بتكوين تطبيق الاختبار والتطوير المستمر. ثم في التطوير ، غيرت بعض مساحات أسماء الخدمات. لذلك قمت بفحص مضاعفة "System.ServicEmodel -> Client -> endpoint -> العقد" في web.config لمطابقة فئة WCF. ثم يتم حل المشكلة.

يجب أن تعكس مساحة الاسم في التكوين بقية مسار مساحة الاسم بعد مساحة الاسم الافتراضية لعميلك (كما تم تكوينها في خصائص المشروع). بناءً على إجابتك المنشورة ، أظن أن عميلك تم تكوينه ليكون في مساحة اسم "Fusion.Dataexchange.workflows". إذا قمت بنقل رمز العميل إلى مساحة اسم أخرى ، فستحتاج إلى تحديث التكوين لمطابقة مسار مساحة الاسم المتبقية.

فقط لأي شخص آخر مع نفس المشكلة ؛ كتبت اختبار الوحدة لطريقتي التي حاولت الاتصال بخدمتي. لقد فشل في هذا الاستثناء نفسه في كل مرة - ليس لدي أي فكرة عن السبب. عندما ركضت من winform ، يعمل بشكل جيد.

لدي نفس المشكلة. لقد استخدمت خدمة WCF في مكتبة الفصل والاتصال بمكتبة الفصل من مشروع تطبيق Windows. لكنني أنسى التغيير <system.serviceModel> في ملف التكوين لمشروع تطبيق Windows نفسه <system.serviceModel> من ملف App.Config الخاص بمكتبة الفصل.
الحل: تغيير تكوين المشروع الخارجي نفسه تكوين WCF لمكتبة الفئة.

إذا قمت بالإشارة إلى خدمة الويب في مكتبة الفصول الدراسية ، فعليك نسخ App.Config إلى تطبيق Windows أو وحدة التحكم الخاصة بك

الحل: تغيير تكوين المشروع الخارجي نفسه تكوين WCF لمكتبة الفئة.

عملت بالنسبة لي

مرحبًا ، لقد واجهت نفس المشكلة ولكن الحل الأفضل هو السماح لـ .NET بتكوين تكوين جانب العميل الخاص بك. ما اكتشفته هذا عندما أضيف مرجع خدمة مع سلسلة استعلام من http: /namespace/service.svc؟ wsdl = wsdl0 لا ينشئ نقاط نهاية التكوين في جانب العميل. ولكن عندما أقوم بإزالة؟ WSDL-WSDL0 واستخدم فقط عنوان URL http: /namespace/service.svc ، فإنه ينشئ تكوين نقطة النهاية في ملف تكوين العميل. ل remoe القصير "؟ wsdl = wsdl0".

لا تضع خط إعلان عميل الخدمة كحقل فئة ، بدلاً من ذلك ، قم بإنشاء مثيل في كل طريقة المستخدمة. لذلك سيتم إصلاح المشكلة. إذا قمت بإنشاء مثيل عميل الخدمة كحقل فئة ، فإن خطأ وقت التصميم يحدث!

In case if you are using WPF application using PRISM framework then configuration should exist in your start up project (i.e. in the project where your bootstrapper resides.)

This error can arise if you are calling the service in a class library and calling the class library from another project.

There seem to be several ways to create/fix this issue. For me, the CRM product I am using was written in native code and is able to call my .NET dll, but I run into the configuration information needing to be at/above the main application. For me, the CRM application isn't .NET, so I ended up having to put it in my machine.config file (not where I want it). In addition, since my company uses Websense I had a hard time even adding the Service Reference due to a 407 Proxy Authentication Required issue, that to required a modification to the machine.cong.

Proxy solution:

To get the WCF Service Reference to work I had to copy the information from the app.config of my DLL to the main application config (but for me that was machine.config). And I also had to copy the endpoint information to that same file. Once I did that it starting working for me.

Ok. My case was a little diffrent but finally i have found the fix for it: I have a Console.EXE -> DLL -> Invoking WS1 -> DLL -> Invoking WS2

I have had both the configurations of the service model of WS1, and WS2 in the Console.EXE.config as recommended. - didnt solve the issue.

But it still didn't work, until i have added the WebReference of WS2 to WS1 also and not only to the DLL that actually creating and invoking the proxy of WS2.

I had the same Issue
I was using desktop app and using Global Weather Web service

I deleted the service reference and added the web reference and problem solved Thanks

Solution for me was to remove the endpoint name from the Endpoint Name attribute in client web.config this allowed the proxy to use

ChannelFactory<TService> _channelFactory = new ChannelFactory<TService>("");

only took all day to work out. Also the contract name was wrong once this fix was in place although it had been wrong when the initial error appear. Double then triple check for contract name strings people !! attrib: Ian

Allow me to add one more thing to look for. (Tom Haigh's answer already alludes to it, but I want to be explicit)

My web.config file had the following defined:

<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>

I was already using basicHttpsBinding for one reference, but then I added a new reference which required basicHttpBinding (no s). All I had to do was add that to my protocolMapping as follows:

<protocolMapping>
    <add binding="basicHttpBinding" scheme="http" />
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>

As L.R. correctly points out, this needs to be defined in the right places. For me, that meant one in my Unit Test project's app.config as well as one in the main service project's web.config.

I had this error when I was referencing the Contract in the configuration file element without the global scope operator.

i.e.

<endpoint contract="global::MyNamepsace.IMyContract" .../>

works, but

<endpoint contract="MyNamepsace.IMyContract" .../>

gives the "Could not find default endpoint element that references contract" error.

The assembly containing MyNamepsace.IMyContract is in a different assembly to the main application, so this may explain the need to use the global scope resolution.

I got same error and i try some many thing but didn't work, than i noticed that my "contract" was not same for whole projects, i changed the contract as would be same for all projects inside solution and than it worked. This is project A

<client>
    <endpoint address="https://xxxxxxxx" binding="basicHttpBinding" bindingConfiguration="basic" contract="ServiceReference.IIntegrationService" name="basic" />
</client>

Project B :

<client>
    <endpoint address="xxxxxxxxxxxxx" binding="basicHttpBinding" bindingConfiguration="basic" contract="ServiceReference1.IIntegrationService" name="basic" />
</client>

Finally I changed for both as :

<client>
    <endpoint address="https://xxxxxxxxxxx" binding="basicHttpBinding" bindingConfiguration="basic" contract="MyServiceReferrence.IIntegrationService" name="basic" />
</client>

When you are adding a service reference

enter image description here

beware of namespace you are typing in:

enter image description here

You should append it to the name of your interface:

<client>
  <endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
            binding="basicHttpBinding" 
            contract="MyNamespace.IMySOAPWebService" />
</client>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top