WCF Web服务错误(找不到引用契约的默认端点元素)

时间:2022-07-08 16:49:17

I've spent hours trying to figure out this particular error and have had no luck.

我花了好几个小时试图找出这个特殊的错误并且没有运气。

I keep getting an error reading like I'm missing an endpoint and I'm new to WCF web Services so I'm not sure what direction to look. Anyway, The error reads.

我一直收到错误,因为我错过了一个端点,而且我是WCF网络服务的新手,所以我不确定要查看的方向。无论如何,错误读取。

Could not find default endpoint element that references contract 'ServiceReference1.ServiceContract' 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.

无法在ServiceModel客户端配置部分中找到引用合同“ServiceReference1.ServiceContract”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

I create the object like this and then add a method.

我像这样创建对象,然后添加一个方法。

ServiceReference1.ServiceContractClient test = new ServiceReference1.ServiceContractClient(); var connecting = test.Connect();

ServiceReference1.ServiceContractClient test = new ServiceReference1.ServiceContractClient(); var connecting = test.Connect();

I have endpoints in my web.config file of the WcfProject. Here's my web.config

我在WcfProject的web.config文件中有端点。这是我的web.config

    <?xml version="1.0"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
      <sessionState cookieless="false" mode="InProc"/>
      <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
      </system.web>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="X-UA-Compatible" value="IE=edge" />
                <add name="Access-Control-Allow-Origin" value="*" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="RestBinding"></binding>
            </webHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="ServiceBehavior" name="WcfRestService1.Service">
                <endpoint name="ServiceBinding" contract="WcfRestService1.IService" binding="webHttpBinding" bindingConfiguration="RestBinding" behaviorConfiguration="RestBehavior" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <endpoint address="basic" binding="wsHttpBinding" bindingConfiguration="" contract="WcfRestService1.IService" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://servername/WcfRestService1/Service.svc" />
                    </baseAddresses>
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="RestBehavior">
                    <webHttp helpEnabled="true" />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <client>
            <endpoint name="Default"
                      address="http://servername/WcfRestService1/Service.svc"
                      binding="webHttpBinding"
                      bindingConfiguration="RestBinding"
                      behaviorConfiguration="RestBehavior"
                      contract="WcfRestService1.IService" />
        </client>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    </system.serviceModel>
</configuration>

I'm not sure what i need.

我不确定我需要什么。

Thanks for any help.

谢谢你的帮助。

1 个解决方案

#1


0  

You can not consume REST service using Service Proxy generated either by using Visual studio add service reference feature or using svcutil.exe. You need to use WebClient, HttpWebRequest or any other third party library capable of making http calls.

您无法使用通过使用Visual Studio添加服务引用功能或使用svcutil.exe生成的服务代理来使用REST服务。您需要使用WebClient,HttpWebRequest或任何其他能够进行http调用的第三方库。

#1


0  

You can not consume REST service using Service Proxy generated either by using Visual studio add service reference feature or using svcutil.exe. You need to use WebClient, HttpWebRequest or any other third party library capable of making http calls.

您无法使用通过使用Visual Studio添加服务引用功能或使用svcutil.exe生成的服务代理来使用REST服务。您需要使用WebClient,HttpWebRequest或任何其他能够进行http调用的第三方库。