更改 WCF 服务参考中的大小写
我正在创建对用 Java 编写的 Web 服务的服务引用。生成的类现在遵循 Web 服务中使用的 Java 大小写约定,例如类名是驼峰命名法而不是 PascalCase。
有没有办法从服务参考中获取所需的外壳?
澄清:
使用基于 WSE 的服务,可以修改生成的 Reference.cs 以提供 .NET 标准大小写,并使用 XmlElementAttribute 映射到外部 Web 服务提供的 Java 命名,如下所示:
[System.Xml.Serialization.XmlElementAttribute("resultType", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Runtime.Serialization.DataMember]
public virtual MyResultType ResultType
{ ... }
如果不编写自定义代码,则不太易于维护生成代理代码或在生成后对其进行修改。
我所追求的是使用 .NET 大小写约定向调用应用程序提供 WCF 生成的客户端代理的一个或多个选项,实现与我之前使用 WSE 所做的相同的效果。希望减少手动工作。
I'm creating a service reference to a web service written in Java. The generated classes now follow the Java casing convention used in the web service, for example class names are camelCase rather than PascalCase.
Is there a way to get the desired casing from the service reference?
CLARIFICATION:
With WSE based services, one could modify the generated Reference.cs to provide .NET standard casing and use XmlElementAttribute to map to the Java naming presented by the external web service, like this:
[System.Xml.Serialization.XmlElementAttribute("resultType", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Runtime.Serialization.DataMember]
public virtual MyResultType ResultType
{ ... }
Not terribly maintenance-friendly without writing custom code to either generate the proxy code or modify it after it's been generated.
What I'm after is one or more options to present a WCF generated client proxy to calling applications using the .NET casing conventions, achieving the same as I did previously with WSE. Hopefully with less manual effort.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,由于您的 WCF 客户端代理是部分类,因此您始终可以为同一个类添加第二个文件,该文件为每个
javaCasedMethodName
实现PascalCasedMethodName
> 然后从新方法中调用 Java 方法。看起来有点多余 - 但我认为这应该确实有效。由于您的代码存储在单独的文件中,因此如果您重新创建客户端代理,它不会被覆盖 - 并且由于它是分部类的第二部分,因此它将“合并到”客户端代码的类定义中打电话。
Well, since your WCF client proxies are partial classes, you could always add a second file for the same class, which implements the
PascalCasedMethodName
for eachjavaCasedMethodName
and then just call the Java method from your new method.Seems a bit redundant - but that should really work, I think. Since your code is stored in a separate file, it won't be overwritten if you re-create the client proxy - and since it's the second part of a partial class, it will be "merged into" the class definition for your client code to call.