0
我從我的服務wsdl中使用wsdl.exe獲取wsdl.cs。然後通過調用CSharpCodeProvider生成dll。WebService序列化請求丟失可空屬性
現在我使用dll,創建一個客戶端來調用該服務,但是一些可爲空的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;
}
}
}
我這樣調用
UPGProcess client = new UPGProcess();
UnifiedRequest request111 = new UnifiedRequest()
{
OrderInfo = new OrderInfo()
{
CompanyCode = "1003",
PayTermsCode = "002",
Amount = 100.98M,
ShippingAmount = 0.00M,
TaxAmount = 0.00M,
CurrencyCode = "USD",
OrderNumber = 109913159,
OrderDateTime = DateTime.Parse("2012-10-24 23:36:45"),
CustomerNumber = 10000,
CustomerCreateDate = DateTime.Parse("2007-03-23T06:41:25.197"),
Email = "[email protected]",
IPAddress = "138.54.191.55",
ShippingMethod = "G",
PartialAuth = "Y",
AddressHistory = "330",
AddressQuality = "Y",
OrderCount = "15",
Password = "sd/fds==",
RedeemedGCAmount = "0.00",
RedeemedGCQuantity = "0",
RushOrder = "N",
SalesChannel = "E33",
ShipViaCode = "006",
},
};
var ddd = client.SendRequest(request111);
和SOAP服務是
<?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>[email protected]</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>
可以看到銅stomerNumber丟失。有人可以幫助我嗎?