有一个specific WSDL为此,ServiceContractGenerator 不断生成消息契约(Contract)(请求/响应包装器对象),这是我不想要的(我想要直接参数)。其他 WSDL 工作正常。
当我使用 Visual Studio 创建 WCF 客户端(“添加服务引用”)并单击“高级...”时,显示“始终生成消息契约(Contract)”的复选框确实正确地控制了消息契约(Contract)对象是否是生成。
但是,当我使用 ServiceContractGenerator 类以编程方式生成 WCF 客户端时,它会一直生成消息协定。我尝试将 ServiceContractGenerator 的选项设置为 ServiceContractGenerationOptions.None,但结果是一样的。
这是我使用的代码:
MetadataSet metadataSet = new MetadataSet();
metadataSet.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(System.Web.Services.Description.ServiceDescription.Read(wsdlStream)));
WsdlImporter importer = new WsdlImporter(metadataSet);
if (serviceDescription != null)
importer.WsdlDocuments.Add(serviceDescription);
foreach (XmlSchema nextSchema in schemas)
importer.XmlSchemas.Add(nextSchema);
ServiceContractGenerator generator = new ServiceContractGenerator();
generator.Options = ServiceContractGenerationOptions.None;
foreach (ContractDescription nextContract in importer.ImportAllContracts())
generator.GenerateServiceContractType(nextContract);
if (generator.Errors.Count != 0)
throw new Exception("Service assembly compile error: \r\n - " + string.Join("\r\n - ", generator.Errors.Select(e => e.Message)));
// Use generator.TargetCompileUnit to generate the code...
我应该怎么做才能让 ServiceContractGenerator 生成带有直接参数的 web 方法?
最佳答案
When I use Visual Studio to create a WCF client ("Add Service Reference") and I click on "Advanced...", the checkbox which says "Always generate message contracts" does properly control whether the message contract objects are generated.
这是不正确的。从链接尝试使用有问题的 WSDL,您将获得与使用 ServiceContractGenerator 相同的结果。事实上,ServiceContractGenerationOptions.TypedMessages标志(默认关闭)直接对应于上述对话选项,并用于(打开时)强制创建消息契约(Contract)。
话虽如此,问题出在 WSDL 中,并在生成的 .cs 文件中用如下行指出:
// CODEGEN: Generating message contract since element name login from namespace http://localhost/FinSwitch/ is not marked nillable
这就是问题所在。当方法元素或响应元素包含“对象类型”(字符串、base64Binary 等)时,svcutil.exe、“添加服务引用”对话框和ServiceContractGenerator 都不会打开方法) 没有用 nillable="true" 标记的成员。
例如,这是有问题的 WSDL 的一部分:
<s:element name="DownloadFile">
<s:complexType>
<s:sequence>
<s:element type="s:string" name="login" maxOccurs="1" minOccurs="0"/>
<s:element type="s:string" name="password" maxOccurs="1" minOccurs="0"/>
<s:element type="s:string" name="fileType" maxOccurs="1" minOccurs="0"/>
<s:element type="s:dateTime" name="fileDate" maxOccurs="1" minOccurs="1"/>
<s:element type="s:boolean" name="onlyDownloadIfFileChanged" maxOccurs="1" minOccurs="1"/>
<s:element type="s:string" name="companyCode" maxOccurs="1" minOccurs="0"/>
<s:element type="s:string" name="category" maxOccurs="1" minOccurs="0"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="DownloadFileResponse">
<s:complexType>
<s:sequence>
<s:element type="s:base64Binary" name="DownloadFileResult" maxOccurs="1" minOccurs="0"/>
</s:sequence>
</s:complexType>
</s:element>
产生
// CODEGEN: Generating message contract since element name login from namespace http://localhost/FinSwitch/ is not marked nillable
[System.ServiceModel.OperationContractAttribute(Action="http://localhost/FinSwitch/FinSwitchWebServiceSoap/DownloadFileRequest", ReplyAction="http://localhost/FinSwitch/FinSwitchWebServiceSoap/DownloadFileResponse")]
DownloadFileResponse DownloadFile(DownloadFileRequest request);
加上消息联系人类。
但是,如果我们将其修改为:
<s:element name="DownloadFile">
<s:complexType>
<s:sequence>
<s:element type="s:string" name="login" nillable="true" maxOccurs="1" minOccurs="0"/>
<s:element type="s:string" name="password" nillable="true" maxOccurs="1" minOccurs="0"/>
<s:element type="s:string" name="fileType" nillable="true" maxOccurs="1" minOccurs="0"/>
<s:element type="s:dateTime" name="fileDate" maxOccurs="1" minOccurs="1"/>
<s:element type="s:boolean" name="onlyDownloadIfFileChanged" maxOccurs="1" minOccurs="1"/>
<s:element type="s:string" name="companyCode" nillable="true" maxOccurs="1" minOccurs="0"/>
<s:element type="s:string" name="category" nillable="true" maxOccurs="1" minOccurs="0"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="DownloadFileResponse">
<s:complexType>
<s:sequence>
<s:element type="s:base64Binary" name="DownloadFileResult" nillable="true" maxOccurs="1" minOccurs="0"/>
</s:sequence>
</s:complexType>
</s:element>
然后生成的代码如预期的那样
[System.ServiceModel.OperationContractAttribute(Action="http://localhost/FinSwitch/FinSwitchWebServiceSoap/DownloadFileRequest", ReplyAction="http://localhost/FinSwitch/FinSwitchWebServiceSoap/DownloadFileResponse")]
byte[] DownloadFile(string login, string password, string fileType, System.DateTime fileDate, bool onlyDownloadIfFileChanged, string companyCode, string category);
并且没有消息契约类。
这是什么意思?该规则被硬编码在基础设施中(如果有人感兴趣,here 是引用来源)并且不能更改。可以预处理 WSDL 内容(毕竟,它是 XML)并在需要的地方插入 nillable="true",但我不确定这是否可以被认为是正确的操作 - AFAIK,这是服务提供商有责任提供正确的 WSDL,并且不保证更改它不会导致副作用。
关于c# - 防止 ServiceContractGenerator 生成消息契约(请求/响应包装器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27358165/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我是Rails的新手,所以请原谅简单的问题。我正在为一家公司创建一个网站。那家公司想在网站上展示它的客户。我想让客户自己管理这个。我正在为“客户”生成一个表格,我想要的三列是:公司名称、公司描述和Logo。对于名称,我使用的是name:string但不确定如何在脚本/生成脚手架终端命令中最好地创建描述列(因为我打算将其设置为文本区域)和图片。我怀疑描述(我想成为一个文本区域)应该仍然是描述:字符串,然后以实际形式进行调整。不确定如何处理图片字段。那么……说来话长:我在脚手架命令中输入什么来生成描述和图片列? 最佳答案 对于“文本”数
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha