2016-07-18 3 views
1

Это в WCF сервис мой Web.config:Невозможно добавить конечную точку WCF службы в WinForms

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="Mobile55.Service1"> 
     <endpoint address="../Service1.svc" 
      binding="webHttpBinding" 
      contract="Mobile55.IService1" 
      behaviorConfiguration="webBehaviour" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="webBehaviour"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <httpProtocol> 
    <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" /> 
    </customHeaders> 
    </httpProtocol> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <directoryBrowse enabled="true"/> 
    </system.webServer> 

</configuration> 

Это первый раз, когда я работаю с WCF, и я не могу добавить конечную точку для этого сервиса в моем приложении WinForms.

Я добавил эту услугу в качестве ссылки, и я могу получить доступ к методам, но когда я отладка и попытаться вызвать метод он бросает исключение:

Could not find default endpoint element that references contract 'MyService.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

Моего файл приложение app.config пуст.

Я попытался следующие ответы, но не работает для меня:

Could not find default endpoint element

Could not find default endpoint element that references contract - Hosting wcf

WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'

Как добавить конечную точку, чтобы, наконец, быть в состоянии использовать свой оказание услуг?

Заранее спасибо.

EDIT: Мой app.config файл:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<system.serviceModel> 
<services> 
    <service name="Mobile55.Service1"> 
    <endpoint address="" 
     binding="webHttpBinding" 
     contract="Mobile55.IService1" 
     behaviorConfiguration="webBehaviour" /> 
    </service> 
</services> 

<behaviors> 
    <serviceBehaviors> 
    <behavior name="webBehaviour"> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<client> 
    <endpoint address="http://localhost:1008/Service1.svc" 
    binding="webHttpBinding" 
    contract="Mobile55.IService1" 
    behaviorConfiguration="webBehaviour" /> 
</client> 
</system.serviceModel> 
</configuration> 

ответ

0

Ну, сообщение об ошибке конкретно указано в client configuration section. Таким образом, ошибка возникает на стороне клиента, то есть из кода, в котором вы пытаетесь вызвать на свой сервис, - более сложно сказать без правильного исключения/stacktrace и полного/компилируемого примера, демонстрирующего поведение.

Во всяком случае, в вашем файле конфигурации отсутствует раздел client.

Добавить что-то вроде этого:

<system.serviceModel> 
    <!-- ... other stuff you have ... --> 
    <client> 
     <endpoint address="../Service1.svc" 
      binding="webHttpBinding" 
      contract="Mobile55.IService1" 
      behaviorConfiguration="webBehaviour" /> 
    </client> 
</system.serviceModel> 
+0

спасибо. Но после добавления этого раздела теперь я получаю следующее: «Нет никакого поведения конечной точки с именем« webBehaviour » –

+0

Вы действительно _add_ элемент' client' в свой раздел 'system.serviceModel', или вы заменили весь раздел тем, что Я написал? –

+0

Я добавил свой контент app.config выше.Вы можете взглянуть? –

0

Что-то вроде этого следует сделать трюк с надеждой

<service name="MyService.Service1"> 
    <endpoint address="YourEndPointHere" 
     binding="webHttpBinding" 
     contract="MyService.IService1" 
     behaviorConfiguration="webBehaviour" /> 
    </service> 
0

Вы можете попробовать с этим

<service name="Mobile55.Service1"> 
     <endpoint address="" 
      binding="webHttpBinding" 
      contract="Mobile55.IService1" 
      behaviorConfiguration="webBehaviour" /> 
     </service> 

Вы можете позвонить службы отдыха, например,

localhost:port/Service1.svc/Pathname 

Здесь приведено имя Pathname, которое вы упомянули в операции contract uritemplate.

Надеюсь, это поможет!

+0

еще дает ту же ошибку. –

0
<system.serviceModel> 
<client> 
<endpoint address="http://localhost:1008/Service1.svc" 
binding="webHttpBinding" 
bindingConfiguration="webHttpBinding_IService" 
contract="Mobile55.IService1" 
name="webHttpBinding_IService" /> 
</client> 
</system.serviceModel> 


---------- 
## Heading ## 


Try.... 
+0

В 'web.config' или' app.config'? –

+0

web.config ..... – abaravindan

Смежные вопросы