来自C#错误的Comsume WCF

时间:2017-03-13 23:22:32

标签: c# wcf

我有一个C#WCF服务,我试图通过我的C#客户端应用程序消费,但收到错误。以下是有关设置的信息。

Web.Config文件

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfig">
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>


    <services>
      <!-- Note: the service name must match the configuration name for the service implementation. -->
      <service name="Proactive_WebAPI.Services">
        <!-- Add the following endpoint.  -->
        <!-- Note: your service must have an http base address to add this endpoint. -->
        <endpoint
            address="http://api.proactiveclothing.com/services/Product.svc"
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfig"
            contract="Proactive.Product.ProductDataService" />
        <endpoint address="mex"
            binding="mexHttpsBinding"
            contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="../../wsdl/ProductDataService.wsdl"/>
          <!-- 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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>   
  </system.serviceModel>

我已将服务路径添加为我的c#客户端应用程序的参考,这是我用来访问它的代码。

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

    ServiceReference3.GetProductSellableRequest req = new ServiceReference3.GetProductSellableRequest();
    req.password = "xxxxx";
    req.productId = "000";
    f.getProductSellable(req);

例外详细信息

System.ServiceModel.EndpointNotFoundException was unhandled by user code
  HResult=-2146233087
  Message=There was no endpoint listening at http://localhost/ProductDataService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       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 ServiceReference3.ProductDataService.getProductSellable(getProductSellableRequest1 request)
       at ServiceReference3.ProductDataServiceClient.ServiceReference3.ProductDataService.getProductSellable(getProductSellableRequest1 request) in c:\Users\laptop\AppData\Local\Temp\Temporary ASP.NET Files\vs\8c312d07\39684625\App_WebReferences.lc9jzddi.4.cs:line 3477
       at ServiceReference3.ProductDataServiceClient.getProductSellable(GetProductSellableRequest GetProductSellableRequest) in c:\Users\laptop\AppData\Local\Temp\Temporary ASP.NET Files\vs\8c312d07\39684625\App_WebReferences.lc9jzddi.4.cs:line 3483
       at WebService.Page_Load(Object sender, EventArgs e) in d:\Websites\5. Stand Alone Applications\PastelSDK\WebService.aspx.cs:line 26
       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: System.Net.WebException
       HResult=-2146233079
       Message=The remote server returned an error: (404) Not Found.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       InnerException: 

修改

修改客户端中的web.config文件,如下所示

<endpoint address="http://api.proactiveclothing.com/services/Product.svc" binding="basicHttpBinding"
        bindingConfiguration="ProductDataServiceBinding2" contract="ServiceReference3.ProductDataService"
        name="ProductDataServiceBinding1" />

我现在收到以下错误

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 ServiceReference3.ProductDataService.getProductSellable(getProductSellableRequest1 request)
       at ServiceReference3.ProductDataServiceClient.ServiceReference3.ProductDataService.getProductSellable(getProductSellableRequest1 request) in c:\Users\laptop\AppData\Local\Temp\Temporary ASP.NET Files\vs\8c312d07\39684625\App_WebReferences.lc9jzddi.4.cs:line 3477
       at ServiceReference3.ProductDataServiceClient.getProductSellable(GetProductSellableRequest GetProductSellableRequest) in c:\Users\laptop\AppData\Local\Temp\Temporary ASP.NET Files\vs\8c312d07\39684625\App_WebReferences.lc9jzddi.4.cs:line 3483
       at WebService.Page_Load(Object sender, EventArgs e) in d:\Websites\5. Stand Alone Applications\PastelSDK\WebService.aspx.cs:line 27
       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: 

0 个答案:

没有答案