C# WebService序列化请求丢失了Nullable属性

C# WebService序列化请求丢失了Nullable属性,c#,web-services,soap,wsdl,C#,Web Services,Soap,Wsdl,我从我的服务中得到一个wsdl.cs,wsdl使用wsdl.exe。然后通过使用CSharpCodeProvider生成dll 现在我使用dll,创建一个客户端来调用服务,但是一些可为null的int和decimal属性没有序列化到soap消息中。为什么? 这是我的密码 CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters(); cp.Gener

我从我的服务中得到一个wsdl.cs,wsdl使用wsdl.exe。然后通过使用CSharpCodeProvider生成dll

现在我使用dll,创建一个客户端来调用服务,但是一些可为null的int和decimal属性没有序列化到soap消息中。为什么?

这是我的密码

CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.GenerateExecutable = false;
cp.GenerateInMemory = true;
cp.OutputAssembly = dllFileName;
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.XML.dll");
cp.ReferencedAssemblies.Add("System.Web.Services.dll");
cp.ReferencedAssemblies.Add("System.Data.dll");
CompilerResults result = provider.CompileAssemblyFromFile(cp, csFileName);
财产

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("AutoTesting.UI", "1.0.0.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/UnifiedRequest.xsd")]
 public partial class OrderInfo 
{
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<decimal> Amount {
        get {
            return this.amountField;
        }
        set {
            this.amountField = value;
        }
    }
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<int> CustomerNumber {
        get {
            return this.customerNumberField;
        }
        set {
            this.customerNumberField = value;
        }
    }
}
肥皂是

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ...>
    <soap:Body>
        <SendRequest xmlns="http://tempuri.org/">
            <unifiedRequest>
                <OrderInfo xmlns="http://tempuri.org/UnifiedRequest.xsd">
                    <CompanyCode>1003</CompanyCode>
                    <PayTermsCode>002</PayTermsCode>
                    <TransactionID xsi:nil="true" />
                    <CurrencyCode>USD</CurrencyCode>
                    <Email>peterssenleong@gmail.com</Email>
                    <IPAddress>138.54.191.55</IPAddress>
                    <SellerID xsi:nil="true" />
                    <ShippingMethod>G</ShippingMethod>
                    <PartialAuth>Y</PartialAuth>
                    <AddressHistory>330</AddressHistory>
                    <AddressQuality>Y</AddressQuality>
                    <OrderCount>15</OrderCount>
                    <Password>sd/fds==</Password>
                    <RedeemedGCAmount>0.00</RedeemedGCAmount>
                    <RedeemedGCQuantity>0</RedeemedGCQuantity>
                    <RushOrder>N</RushOrder>
                    <SalesChannel>E33</SalesChannel>
                    <ShipViaCode>006</ShipViaCode>
                    <MLResult xsi:nil="true" />
                    <DoubleAddress xsi:nil="true" />
                    <HijackAccount xsi:nil="true" />
                    <ShippingCompanyName xsi:nil="true" />
                    <PONumber xsi:nil="true" />
                    <WillCallName xsi:nil="true" />
                    <WillCallPhone xsi:nil="true" />
                    <VmeCardBlockMatch xsi:nil="true" />
                    <GuestCustomer xsi:nil="true" />
                    <VmeRiskAdvice xsi:nil="true" />
                    <GCDeliveryDate xsi:nil="true" />
                    <GCReceiverEmail xsi:nil="true" />
                    <GCReceiverName xsi:nil="true" />
                    <GCSenderName xsi:nil="true" />
                    <BillingQasLevel xsi:nil="true" />
                    <Distance xsi:nil="true" />
                    <IPBillingSameCity xsi:nil="true" />
                    <IPBillingSameState xsi:nil="true" />
                    <IPCity xsi:nil="true" />
                    <IPCountry xsi:nil="true" />
                    <IPState xsi:nil="true" />
                    <IPZipcode xsi:nil="true" />
                    <ShippingQasLevel xsi:nil="true" />
                    <IsResubmitSO xsi:nil="true" />
                    <IsSplitSO xsi:nil="true" />
                    <ShoppingCartID xsi:nil="true" />
                    <RefundType xsi:nil="true" />
                    <NeweggFlash xsi:nil="true" />
                    <HighVolume xsi:nil="true" />
                    <GoogleEmail xsi:nil="true" />
                    <RedeemedEggPoints xsi:nil="true" />
                </OrderInfo>
        </unifiedRequest>
    </SendRequest>
</soap:Body>
</soap:Envelope>

1003
002
美元
peterssenleong@gmail.com
138.54.191.55
G
Y
330
Y
15
sd/fds==
0
0
N
E33
006
您可以看到缺少CustomerNumber。有人能帮我吗?

我解决了我的问题

这是因为这是OrderInfo类中的CustomerNumber指定属性,默认情况下为false,因此CustomerNumber不会序列化

[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool CustomerNumberSpecified
每次我为CustomerNumber设置值时,我都会为CustomerNumber指定值设置true,这一切都很好

[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool CustomerNumberSpecified