edo*_*oft 361 wcf wcf-binding endpoint .net-3.5
我已经为web服务添加了代理到VS2008/.NET 3.5解决方案.构建客户端.NET时抛出此错误:
无法在ServiceModel客户端配置部分中找到引用合同"IMySOAPWebService"的默认端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.
搜索此错误告诉我在合同中使用完整的命名空间.这是我的带有完整命名空间的app.config:
<client>
<endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
binding="basicHttpBinding" bindingConfiguration="IMySOAPWebServicebinding"
contract="Fusion.DataExchange.Workflows.IMySOAPWebService" name="IMySOAPWebServicePort" />
</client>
Run Code Online (Sandbox Code Playgroud)
我正在运行XP本地(我之所以提到这是因为一些谷歌点击提到win2k3)app.config被复制到app.exe.config,所以这也不是问题.
有线索吗?
小智 579
"如果您在类库中调用服务并从另一个项目调用类库,则会出现此错误."
在这种情况下,如果是winapp,则需要将WS配置设置包含到主项目app.config中,如果是web应用,则需要包含web.config.这是使用PRISM和WPF/Silverlight的方法.
Tom*_*igh 82
我通过自己创建绑定和端点地址实例解决了这个问题(我认为正如其他人所建议的那样) - 因为我不想在配置文件中添加新的设置(这是一些广泛使用的现有库代码的替代品,以前使用过较旧的Web服务参考等),所以我希望能够在不添加新的配置设置的情况下放弃它.
var remoteAddress = new System.ServiceModel.EndpointAddress(_webServiceUrl);
using (var productService = new ProductClient(new System.ServiceModel.BasicHttpBinding(), remoteAddress))
{
//set timeout
productService.Endpoint.Binding.SendTimeout = new TimeSpan(0,0,0,_webServiceTimeout);
//call web service method
productResponse = productService.GetProducts();
}
Run Code Online (Sandbox Code Playgroud)
编辑
如果您使用的是https,那么您需要使用BasicHttpsBinding而不是BasicHttpBinding.
edo*_*oft 75
测试了几个选项后,我终于通过使用来解决这个问题
合同= "IMySOAPWebService"
即在配置中没有完整的命名空间.由于某种原因,全名无法正确解析
And*_*mar 55
我有同样的问题.事实证明,对于Web REFERENCE,您必须提供URL作为构造函数的第一个参数:
new WebService.WebServiceSoapClient("http://myservice.com/moo.aspx");
Run Code Online (Sandbox Code Playgroud)
对于新样式的Web SERVICE REFERENCE,您必须提供一个引用配置中端点条目的名称:
new WebService.WebServiceSoapClient("WebServiceEndpoint");
Run Code Online (Sandbox Code Playgroud)
使用相应的条目Web.config或App.config:
<client>
<endpoint address="http://myservice.com/moo.aspx"
binding="basicHttpBinding"
bindingConfiguration="WebService"
contract="WebService.WebServiceSoap"
name="WebServiceEndpoint" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
非常难以删除隧道视野"它在旧程序中工作"......
Bra*_*avo 16
我有这种情况,我有
现在Consumer项目在<system.serviceModel>我的app.config的Tag中设置了所有相关的配置,它仍然抛出与上面相同的错误.
我所做的只是将相同的标签添加<system.serviceModel>到我的主项目的app.config文件中,最后我们很高兴.
真正的问题,就我的情况而言,它正在读取错误的配置文件.而不是消费者的app.config,它是指主要的proj的配置.我花了两个小时来弄清楚这一点.
mel*_*vas 14
"如果您在类库中调用服务并从另一个项目调用类库,则会出现此错误."
"在这种情况下,你需要将WS配置设置包含到主项目app.config中,如果它是一个winapp或web.config,如果它是一个web应用程序.这是使用PRISM和WPF/Silverlight的方法."
是的,但如果您无法更改主项目(例如Orchard CMS),则可以在项目中保留WCF服务配置.
您需要使用客户端生成方法创建服务助手:
public static class ServiceClientHelper
{
public static T GetClient<T>(string moduleName) where T : IClientChannel
{
var channelType = typeof(T);
var contractType = channelType.GetInterfaces().First(i => i.Namespace == channelType.Namespace);
var contractAttribute = contractType.GetCustomAttributes(typeof(ServiceContractAttribute), false).First() as ServiceContractAttribute;
if (contractAttribute == null)
throw new Exception("contractAttribute not configured");
//path to your lib app.config (mark as "Copy Always" in properties)
var configPath = HostingEnvironment.MapPath(String.Format("~/Modules/{0}/bin/{0}.dll.config", moduleName));
var configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = configPath }, ConfigurationUserLevel.None);
var serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
if (serviceModelSectionGroup == null)
throw new Exception("serviceModelSectionGroup not configured");
var endpoint = serviceModelSectionGroup.Client.Endpoints.OfType<ChannelEndpointElement>().First(e => e.Contract == contractAttribute.ConfigurationName);
var channelFactory = new ConfigurationChannelFactory<T>(endpoint.Name, configuration, null);
var client = channelFactory.CreateChannel();
return client;
}
}
Run Code Online (Sandbox Code Playgroud)
并使用它:
using (var client = ServiceClientHelper.GetClient<IDefaultNameServiceChannel>(yourLibName)) {
... get data from service ...
}
Run Code Online (Sandbox Code Playgroud)
请参阅本文中的详细信息.
小智 13
这个让我疯狂.
我正在使用带有WCF的Silverlight 3 Prism(CAB)
当我在Prism模块中调用WCF服务时,我得到相同的错误:
无法在服务模型客户端配置部分中找到引用合同"IMyService"的默认端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素
事实证明,它在Shell的.xap文件中查找ServiceReferences.ClientConfig文件,而不是在模块的ServiceReferences.ClientConfig文件中.我将我的端点和绑定添加到Silverlight Shell应用程序中的现有ServiceReferences.ClientConfig文件中(它称之为自己的WCF服务).
然后我不得不重建Shell应用程序,为我的Web项目的ClientBin文件夹生成新的.xap文件.
现在这行代码最终有效:
MyServiceClient myService = new MyServiceClient();
Run Code Online (Sandbox Code Playgroud)
mar*_*nky 12
当您面临从类文件引用服务时出现的令人难以置信的错误错误时,有几个响应会找到正确的解决方案:将服务配置信息复制到您的控制台或Windows应用程序的app.config web.config中.这些答案似乎都没有告诉你要复制什么.让我们试着纠正它.
这是我从我的类库的配置文件中复制到我的控制台应用程序的配置文件中的内容,以便为我编写的名为"TranslationServiceOutbound"的服务解决这个疯狂的错误.
你基本上想要system.serviceModel部分内的所有内容:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITranslationServiceOutbound" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://MyHostName/TranslationServiceOutbound/TranslationServiceOutbound.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITranslationServiceOutbound"
contract="TranslationService.ITranslationServiceOutbound" name="BasicHttpBinding_ITranslationServiceOutbound" />
</client>
Run Code Online (Sandbox Code Playgroud)
小智 11
我在ASP.NET应用程序中收到此错误,其中WCF服务已添加到类库中,该类作为bin文件夹中引用的.dll文件添加到ASP.NET应用程序中.要解决此错误,需要将引用WCF服务的类库中的app.config文件中的配置设置复制到ASP.NET站点/应用程序的web.config设置中.
我发现(以及复制到客户端UI的App.config,因为我使用的是类库接口)我必须在绑定的名称前加上服务引用的名称(我的是ServiceReference在下面).
例如:
<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISchedulerService"
contract="ServiceReference.ISchedulerService"
name="BasicHttpBinding_ISchedulerService" />
Run Code Online (Sandbox Code Playgroud)
而不是默认生成的:
<endpoint address="http://localhost:4000/ServiceName" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISchedulerService"
contract="ISchedulerService"
name="BasicHttpBinding_ISchedulerService" />
Run Code Online (Sandbox Code Playgroud)
我有同样的问题,但更改合同命名空间对我不起作用.所以我尝试了.Net 2样式的Web引用而不是.Net 3.5服务引用.那很有效.
要在Visual Studio 2008中使用Web引用,请单击"添加服务引用",然后在出现对话框时单击"高级".在那里你会找到一个选项,让你使用Web引用而不是服务引用.
对使用服务的非库应用程序进行单元测试可能会导致此问题.
其他人输入的信息解决了这个问题的根本原因.如果您正在尝试编写自动化测试用例,并且您正在测试的单元实际上将调用服务接口,则需要将服务引用添加到测试项目中.这是使用库类型错误的应用程序的风格.我没有立即意识到这一点,因为我使用接口的代码不在库中.但是,当测试实际运行时,它将从测试组件运行,而不是测试中的组件.
向单元测试项目添加服务引用解决了我的问题.
小智 6
我有一个在单元测试中的情况.我将app.config文件复制到单元测试项目中.因此单元测试项目还包含端点信息.
我曾经遇到过这个问题。那是因为我还在开发使用WCF服务的接口。我配置了测试应用程序并继续开发。然后在开发中,我更改了一些服务的命名空间。所以我在 web.config 中仔细检查了“system.serviceModel -> client -> endpoint -> contract”以匹配 WCF 类。那么问题就解决了。
| 归档时间: |
|
| 查看次数: |
338049 次 |
| 最近记录: |