带字符串返回值(或参数)的ASMX WebService强制在WCF客户端中生成消息协定

带字符串返回值(或参数)的ASMX WebService强制在WCF客户端中生成消息协定,wcf,asmx,messagecontract,Wcf,Asmx,Messagecontract,我有一个简单的ASMX Web服务,它看起来就是这样 using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel; using System.Web; using System.Web.Services; using System.Xml.Serialization; namespace ContractGenerationTest { [WebService(

我有一个简单的ASMX Web服务,它看起来就是这样

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Web;
using System.Web.Services;
using System.Xml.Serialization;

namespace ContractGenerationTest
{
    [WebService(Namespace = Constants.WebServiceNamespace)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Standard : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hellow World";
        }
    }
}
我还有一个与该服务关联的WCF客户端。“始终生成消息契约”复选框未选中。WCF客户端正在生成消息协定类,尽管我不希望它这样做

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://sampleuri.org/ContractGenerationTest/", ConfigurationName="StandardService.StandardSoap")]
public interface StandardSoap {

    // CODEGEN: Generating message contract since element name HelloWorldResult from namespace http://sampleuri.org/ContractGenerationTest/ is not marked nillable
    [System.ServiceModel.OperationContractAttribute(Action="http://sampleuri.org/ContractGenerationTest/HelloWorld", ReplyAction="*")]
    ContractGenerationTestClient.StandardService.HelloWorldResponse HelloWorld(ContractGenerationTestClient.StandardService.HelloWorldRequest request);

    [System.ServiceModel.OperationContractAttribute(Action="http://sampleuri.org/ContractGenerationTest/HelloWorld", ReplyAction="*")]
    System.Threading.Tasks.Task<ContractGenerationTestClient.StandardService.HelloWorldResponse> HelloWorldAsync(ContractGenerationTestClient.StandardService.HelloWorldRequest request);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.ServiceModel”,“4.0.0.0”)]
[System.ServiceModel.ServiceContractAttribute(命名空间=”http://sampleuri.org/ContractGenerationTest/,ConfigurationName=“StandardService.StandardSoap”)]
公共接口标准SOAP{
//CODEGEN:从命名空间生成元素名HelloWorldResult之后的消息协定http://sampleuri.org/ContractGenerationTest/ 不标记为零
[System.ServiceModel.OperationContractAttribute(操作=”http://sampleuri.org/ContractGenerationTest/HelloWorld“,ReplyAction=“*”)]
ContractGenerationTestClient.StandardService.HelloWorldResponse HelloWorld(ContractGenerationTestClient.StandardService.HelloWorldRequest请求);
[System.ServiceModel.OperationContractAttribute(操作=”http://sampleuri.org/ContractGenerationTest/HelloWorld“,ReplyAction=“*”)]
System.Threading.Tasks.Task HelloWorldAsync(ContractGenerationTestClient.StandardService.HelloWorldRequest请求);
}
注意
CODEGEN
注释。这似乎是这样构造的,因为ASMX服务的WSDL中,
string
类型没有标记为nillable。它没有标记为nillable(maxOccurs=1),因为
string.Empty
提供了默认值

如果字符串是复杂类型的成员,我可以将它们标记为
[xmlement(IsNullable=true)]
,这样就解决了问题。。。但我不能在这里这样做,因为它们是函数定义的一部分


有没有已知的解决方案?有没有办法让我的ASMX在WSDL中将字符串参数和返回类型标记为nillable?或者,我的WCF客户端是否有办法停止生成消息契约,即使存在不可为零的参数类型(知道这将删除参数可选性)?

我找到了解决方案。看起来这是使用默认选中的DataContractSerializer的结果。VisualStudio中提供的GUI中没有对此进行修复。要手动配置,请打开服务客户端上的Reference.svcmap文件,并将
Auto
更改为
XmlSerializer
。 这导致VS停止生成消息协定