- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是关于如何使该死的 WCF 自动生成的客户端工作的。易于复制,所有元素都在这里,只需复制和粘贴,只需要一个命令提示符。
在cmd.exe
中:
: set up environment
"%VS100COMNTOOLS%"\vsvars32.bat
: create test directory
md wsc
cd wsc
set url=http://xsc-demo.xlogics.eu/DEMO/XTraceWCF/XTrace.svc?wsdl
svcutil /language:cs /config:app.config %url%
notepad app.config
: change client/endpoint/@name to "Gurke" (or whatever)
copy ..\Test.cs .
csc /appconfig:app.config XTrace.cs Test.cs
Test.cs
是:
class Test {
static void Main() {
XTraceClient client;
// client = new XTraceClient();
client = new XTraceClient( "Gurke" ); // match app.config
client.Close();
}
}
为您留下以下文件:
1.501 app.config
193 Test.cs
31.744 Test.exe
69.284 XTrace.cs
以及生成的客户端代码中的(我认为)相关部分:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://xlogics.eu/xtrace", ConfigurationName="IXTrace")]
public interface IXTrace
如您所见,它具有 ConfigurationName="IXTrace"
和 public interface IXTrace
。
运行 Test.exe
产生以下异常:
System.InvalidOperationException:
Could not find endpoint element with name 'Gurke'
and contract 'IXTrace'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 name
could be found in the client element.
但是,我的 app.config
似乎是匹配的(为了便于阅读,省略了不相关的部分):
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="XTrace" ... >
<readerQuotas ... />
<security mode="None">
<transport ... />
<message ... />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint
address="http://xsc-demo.xlogics.eu/DEMO/XTraceWCF/XTrace.svc"
binding="basicHttpBinding"
bindingConfiguration="XTrace"
contract="IXTrace"
name="Gurke" />
</client>
</system.serviceModel>
</configuration>
如您所见,@contract
是IXTrace
,@name
是Gurke
。那么不匹配从何而来?
将 ConfigurationName="IXTrace"
更改为 ConfigurationName="Gurke"
并重新编译并不能解决问题:同样的错误。
关于这个特定的问题就这么多了。更大的问题是了解这些点点滴滴应该如何一起发挥作用,这样您就可以停止在操作方法模式下工作,并停止用头撞配置问题的墙(如果谷歌有任何指示,这并不罕见)。欢迎指点。
更新
在 app.config
中:
<endpoint name="Heinz" contract="moin.moin.IXTrace" ...
在XTrace.cs
中:
namespace moin.moin {
[System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(
Namespace="http://xlogics.eu/xtrace",
ConfigurationName="moin.moin.IXTrace")]
public interface IXTrace { ...
和测试程序:
using moin.moin;
class Test {
static void Main() {
XTraceClient client = new XTraceClient( "Heinz" );
client.Close();
}
}
为什么不起作用?
更新 2
解决方案在对 Sixto 的回答的评论中。它没有工作,因为该死的配置文件的名称错误并且没有被查阅。事实上,我不需要它来编译,一个简单的 csc Test.cs XTrace.cs
就足够了。配置文件只需与 EXE 名称匹配,因此对于 Test.exe
,它应该是 Test.exe.config
。
最佳答案
确保契约属性(在 system.serviceModel/client/endpoint 元素中)包含 IXTrace 接口(interface)的完全限定命名空间。在 XTrace.cs 文件中搜索 C# 命名空间声明。如果接口(interface)声明为以下代码,则契约(Contract)属性应包含“YourService.IXTrace”:
namespace YourService
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(
Namespace="http://xlogics.eu/xtrace",
ConfigurationName="IXTrace")]
public interface IXTrace
{
//Rest of generated code
}
}
关于c# - WCF,svcutil.exe : How to properly match or configure web service client code?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7076246/
我读了一本书“Pro c# 2010 and the .net 4 Platform”Andrew Troelsen。我停留在第 926 页“使用svcutil.exe"如果我使用的是 Visual
我正在使用模式优先的 Web 服务开发方法,方法是手动编码 WSDL/XSD,然后将其提供给 svcutil 工具以生成 .NET 数据和服务契约(Contract)。我试图通过将“UsingAddr
在谷歌搜索了一下之后,对于 Visual Studio 2008 是否使用 svcutil.exe 没有明确的答案? Visual Studio 2005 确实使用了它,但是 Visual Studi
我开发了一个 WCF 服务,它使用具有所需客户端证书的传输安全性。 它托管在 IIS 7.5 上,需要检查客户端证书。 我已经设置了一个 mex 端点,并且能够在我的浏览器中查看 wsdl https
我正在开发一个使用契约(Contract)优先方法的项目。我得到了一个 WSDL和三个 xsd's .当我使用 svcutil它围绕响应类生成一个包装器,如下所示: public partial cl
我有 wcf 服务。我尝试通过 svcutil 为客户端程序生成代理代码和配置文件: svcutil http://localhost/WcfService2/Files.svc 我通过代理获得了有效
我使用其他人的一些应用程序。现在,是时候更新一些服务和功能了。我向我的旧 wsdl 文件添加了新操作,并且我想使用 svcutil 为我的应用程序生成代码。我正在使用 C:\Program Files
我正在使用来自网络服务的 svcutil 生成数据契约(Contract)。 svcutil /language:cs /noConfig /targetclientversion:Version35
我有一个公开了 soap 和 xml 端点的 WCF 服务。当我使用 svcutil 在客户端生成代理代码时,生成的配置包含两个导致客户端失败的端点。如果我编辑 web.config 文件并删除第二个
我正在尝试使用我编写的 WCF 服务,但我无法获取 svcutil.exe 来生成代理。 我尝试的每条路径都会出现访问被拒绝...我需要设置什么才能获得许可? Generating files...
我试图通过使用 svcutil.exe 创建 WCF 代理来使用使用 WSDL 指定的 Web 服务,但 WSDL 指定某些操作具有可选参数 (minOccurs="0"),例如: 不幸的是,生成的
我想运行 svcutil.exe用于访问 Internet 上的 Web 服务的工具。不幸的是,每当我尝试时,都会收到一堆错误,其中包括以下消息: The request failed with HT
我试图通过SvcUtil.Exe工具生成代理,如果该工具在Visual Studio命令行中提供的话。我已经检查了它所在的默认目录,并且看到可执行文件位于以下目录中 C:\Program Files
我们有目前使用用户名和密码保护的 OSB 服务。我在尝试使用 svcutil 生成服务代理时收到 401 未授权。我知道您需要设置一个 svcutil.exe.config 文件,但除了通过证书的示例
我整天都在和 SvcUtil 搏斗,试图让它为一些 IMS 企业服务(主要是组管理服务,但我们也需要它来工作)生成有用的代码。你可以在这里找到 IMS 服务 WSDL http://www.imsgl
我尝试调用 svcutil.exe 并指定命名空间参数,但无论我做什么,即使我重用来自 Internet 的工作示例,也会收到错误。 例如,在这里我尝试了最简单的选项只是为了测试 - /namespa
我编译了一个新的 WCF 应用程序,运行时出现错误 "The dependent tool 'svcutil.exe' is not found. " 谁能告诉我该怎么做吗? 最佳答案 要解决此问题,
我试图通过命令行生成我的解决方案的服务引用,所以我一直在尝试使用 svcutil 来完成。我有两个问题。 在 Visual Studio 2012 中,我可以指定 System.Array 集合类型和
当 VS.NET 中的添加服务引用提供了您需要的所有代理类时,为什么有人会使用 SvcUtil.exe? 最佳答案 有时在 VS 中添加服务引用无法创建有用的代理。相反,它会为您提供一个空的 Refe
是否可以通过 svcutil 只为一种方法生成异步 ServiceOperation? 我知道我可以添加 /async 参数,但它会以异步模式生成所有方法。 最佳答案 /async 选项允许您生成同步
我是一名优秀的程序员,十分优秀!