我试着用了两个星期来让这个工作仍然没有:(
这是WCF网址> http://api.proactiveclothing.com/services/Product.svc
我在Visual Studio中将其添加为服务引用。
当我访问以下代码时。
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项目中生成了数据和服务合同,该项目已上传到我们的Web服务器。当我尝试从我的本地Web应用程序访问WCF项目时,它会如上所述进行轰炸。
编辑 - 以下是有关WCF服务的信息
web.config中的system.servicemodel
<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="ProductDataService">
<!-- 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="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="http://api.proactiveclothing.com/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>
从wsdl和xsd文件生成的服务和数据合同 注意:仅添加部分文件,因为它太大
namespace Proactive.Product
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://api.proactiveclothing.com/WSDL/ProductDataService/v1/", ConfigurationName = "ProductDataService")]
public interface ProductDataService
{
}
}
WCF Product.svc类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Proactive.Product;
using System.Collections;
namespace Proactive_WebAPI.Services
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Product" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Product.svc or Product.svc.cs at the Solution Explorer and start debugging.
public class Product : Proactive.Product.ProductDataServiceClient
{
public GetProductSellableResponse getProductSellable(GetProductSellableRequest _GetProductSellableRequest)
{
//check passsowrd is valid
if (_GetProductSellableRequest.password != "xxxx")
return null;
//if valid, proceed
GetProductSellableResponse rep = new GetProductSellableResponse();
//try
//{
// List<Proactive_WebAPI.Models.Product> products = ProductDB.GetSellableProducts();
// GetProductSellableResponseProductSellable[] p = new GetProductSellableResponseProductSellable[products.Count];
// int i = 0;
// foreach (Proactive_WebAPI.Models.Product _prod in products)
// {
// p[i].productId = _prod.Id.ToString();
// rep.ProductSellableArray = p;
// i++;
// }
//}
//catch
//{
// rep.ErrorMessage.code = 999;
// rep.ErrorMessage.description = "General Error – Contact the System Service Provider";
//}
rep.ErrorMessage.code = 999;
rep.ErrorMessage.description = "General Error – Contact the System Service Provider";
return rep;
}
}
}
答案 0 :(得分:0)
尝试使用svcutil工具生成引用。如果仍然无法正常工作,你可以尝试删除所有的物理参考文件并重新添加,你知道这种奇怪的东西就会发生。
答案 1 :(得分:0)
我们得到了StfBln的所有功劳,他帮助我聊天。
首先,我必须确保svc类继承自服务,而不是像下面的行那样继承客户端
public class Product : Proactive.Product.ProductDataService
还清理了生成的代码并更改了此
[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只有一行如下行
[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