シンプルな ASMX WebService があり、次のようになります
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);
}
CODEGEN
コメントに注意してください。string
これは、ASMX サービスの WSDL で型が nillable としてマークされていないため、このように構築されているようです。string.Empty
デフォルト値を提供するため、nillable としてマークされていません (maxOccurs=1 もありません) 。
文字列が複合型のメンバーである場合は、それらをマークするだけ[XmlElement(IsNullable=true)]
で問題は解決しますが、関数定義の一部であるため、ここではできません。
これに対する既知の解決策はありますか?ASMX を取得して、WSDL で文字列パラメーターと戻り値の型を nillable としてマークする方法はありますか? または、Nillable でないパラメーター型がある場合でも、WCF クライアントがメッセージ コントラクトの生成を停止する方法はありますか (これにより、パラメーターのオプション性が削除されることがわかっています)。