我从服务wsdl获取wsdl.cs使用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;
}
}
}
我这样称呼服务
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 = "peterssenleong@gmail.com",
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);
和肥皂是
<?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>
您可以看到缺少CustomerNumber。有人可以帮助我吗?
答案 0 :(得分:1)
我解决了我的问题。
那是因为这是OrderInfo类中的CustomerNumberSpecified属性,默认情况下它是false,因此CustomerNumber不会被序列化。
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool CustomerNumberSpecified
每次我为CustomerNumber设置值时,我为CustomerNumberSpecified设置了true,一切正常。