C# C找不到引用协定的默认终结点元素

C# C找不到引用协定的默认终结点元素,c#,wcf,C#,Wcf,我花了两周的时间试图让它正常工作,但仍然一无所获: 这是WCF Url> 我在VisualStudio中将其作为服务引用添加 当我访问下面的代码时 ServiceReference1.ProductDataServiceClient f = new ServiceReference1.ProductDataServiceClient(); ServiceReference1.GetProductSellableRequest req = new ServiceR

我花了两周的时间试图让它正常工作,但仍然一无所获:

这是WCF Url>

我在VisualStudio中将其作为服务引用添加

当我访问下面的代码时

        ServiceReference1.ProductDataServiceClient f = new ServiceReference1.ProductDataServiceClient();

        ServiceReference1.GetProductSellableRequest req = new ServiceReference1.GetProductSellableRequest();
        req.password = "xxxxx";
        req.productId = "148";
        ServiceReference1.GetProductSellableResponse resp = f.getProductSellable(req);
我在最后一行得到以下错误

System.ServiceModel.FaultException`1 was unhandled by user code
  HResult=-2146233087
  Message=Could not find default endpoint element that references contract 'ProductDataService' 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.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at ServiceReference1.ProductDataService.getProductSellable(getProductSellableRequest1 request)
       at ServiceReference1.ProductDataServiceClient.ServiceReference1.ProductDataService.getProductSellable(getProductSellableRequest1 request) in c:\Users\laptop\AppData\Local\Temp\Temporary ASP.NET Files\vs\45e2a7e3\d169f135\App_WebReferences.qunwmnb1.0.cs:line 3522
       at ServiceReference1.ProductDataServiceClient.getProductSellable(GetProductSellableRequest GetProductSellableRequest) in c:\Users\laptop\AppData\Local\Temp\Temporary ASP.NET Files\vs\45e2a7e3\d169f135\App_WebReferences.qunwmnb1.0.cs:line 3528
       at _Default.Page_Load(Object sender, EventArgs e) in d:\Websites\5. Stand Alone Applications\WebSite1\Default.aspx.cs:line 20
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 
这是我的Web.Config文件

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="ProductDataServiceBinding"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://api.proactiveclothing.com/services/Product.svc" binding="basicHttpBinding" bindingConfiguration="ProductDataServiceBinding" contract="ServiceReference1.ProductDataService" name="ProductDataService"/>
    </client>
  </system.serviceModel>
</configuration>
WCF Product.svc类


尝试使用svcutil工具生成引用。如果仍然不工作,您可以尝试删除所有物理参考文件,然后再次添加,您知道这种奇怪的事情会发生。

我们得到了它的工作,所有功劳都归功于帮助我聊天的StfBln

首先,我必须确保svc类是从服务继承的,而不是像下面这样从客户端继承的

public class Product : Proactive.Product.ProductDataService
[System.ServiceModel.OperationContractAttribute(Action = "getProduct")]
还清理了生成的代码并更改了此设置

 [System.ServiceModel.ServiceContractAttribute(Namespace = "http://api.proactiveclothing.com/WSDL/ProductDataService/v1/", ConfigurationName = "ProductDataService")]
对此

[System.ServiceModel.ServiceContractAttribute(Namespace = "http://api.proactiveclothing.com/WSDL/ProductDataService/v1/")]
另外,请确保OperationContractAttribute仅具有类似于第行的操作

public class Product : Proactive.Product.ProductDataService
[System.ServiceModel.OperationContractAttribute(Action = "getProduct")]
使用以下代码行确保生成正确的服务合同,请注意/servicecontract命令

svcutil.exe yourdomain.com/wsdl/ProductDataService.wsdl /language:C# /out:"C:\Users\IEG-WS02\Desktop\WSDL\IService2.cs" /t:code /serviceContract

该服务必须引用另一个服务,这就是您收到的错误。WCF测试工具提供了相同的结果。似乎不是来自您的代码。请告诉我如何解决该服务的正确方向。这两个星期我都快发疯了:这是你的服务吗?您有权访问它的配置文件吗?一端缺少引用。您的客户端设置似乎很好,因为它是由VS成功生成的。请将WCF配置作为问题的一部分,以便进一步排除故障。让我们来看看。
svcutil.exe yourdomain.com/wsdl/ProductDataService.wsdl /language:C# /out:"C:\Users\IEG-WS02\Desktop\WSDL\IService2.cs" /t:code /serviceContract