我正在使用ASP.NET和C#显示一个表单,供某人在点击按钮时完成并向外部公司提交请求。该公司提供了一个WSDL文件,我可以将其作为Web引用导入到我的解决方案中。一旦我添加了引用,它就生成了一堆类,这些类似乎创建了一个XML文件,据我所知,我需要做什么。我给出了一个XML文件提交的示例,但我对如何使用Web引用并提交请求感到困惑。
以下是WSDL
我正在尝试调用complextype(方法)ClaimSubmittalRequest 这是我在C#代码中可以做的(获取并设置字段):
var submitClaim = new ThermalKing.SubmitClaimRequest
{
claimLanguage = "ENG",
serviceVersion = "1.0",
claimType = "PARTS",
failureDate = new DateTime(2014, 11, 26),
faultFound = "PERFORM A FREE INSPECTION"
};
var submitParts = new ThermalKing.eachPart
{
partNumber = "1234",
partPrice = 100.78,
partQuantity = 17
};
以下是示例XML文件的样子:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:get="http://data-test.thermoking.com/ThermoKingWebServices/SubmitClaim/getSubmitClaimWSD">
<soapenv:Header/>
<soapenv:Body>
<get:getSubmitClaim>
<SubmitClaimRequest>
<buName>Thermo King TSA</buName>
<dealerNumber>P5358</dealerNumber>
<userName></userName>
<password></password>
<transactionType>WARRANTY</transactionType>
<claimType>Machine</claimType>
<inventorySerialNumber>6001061225</inventorySerialNumber>
<repairDate>2011-09-05T00:00:00.000-05:00</repairDate>
<failureDate>2011-09-05T00:00:00.000-05:00</failureDate>
<workOrderNumber>testProcede1</workOrderNumber>
<conditionsFound>test</conditionsFound>
<workPerformed>test</workPerformed>
<claimNotes>test claim notes</claimNotes>
<!-- will be optional fields in the future -->
<faultLocation>FF</faultLocation>
<faultFound>BLOWN/BURST</faultFound>
<failureDetail xsi:nil="true"/>
<smrClaim>N</smrClaim>
<forceToDraft>Y</forceToDraft>
<validateOnly>N</validateOnly>
<commercialPolicy>N</commercialPolicy>
<!-- will be optional fields in the future -->
<fuelSurcharge>0</fuelSurcharge>
<shopSupplies>0</shopSupplies>
<claimCurrency>USD</claimCurrency>
<workOrderSegment>1</workOrderSegment>
<claimLanguage>ENG</claimLanguage>
<serviceVersion>1.0</serviceVersion>
<partsType>
<!--1 or more repetitions:-->
<eachPart>
<partType>IRREMOVED</partType>
<partNumber>416780</partNumber>
<partQuantity>1.0</partQuantity>
<partPrice>1.23</partPrice>
<partDescription>test part desc</partDescription>
</eachPart>
<eachPart>
<partType>NONIR</partType>
<partNumber>1</partNumber>
<partQuantity>1.0</partQuantity>
<partPrice>1</partPrice>
<partDescription>test non IR</partDescription>
</eachPart>
<eachPart>
<partType>IRINSTALLED</partType>
<partNumber>416780</partNumber>
<partQuantity>1.0</partQuantity>
<partPrice>1</partPrice>
<partDescription>test ir installed</partDescription>
</eachPart>
</partsType>
<jobCodesType>
<!--1 or more repetitions:-->
<eachJobCode>
<jobCode>05051</jobCode>
<standardLaborHours>1</standardLaborHours>
<additionalLaborHours>.5</additionalLaborHours>
<laborRate>92.22</laborRate>
<ReasonForAdditionalLaborHours>test</ReasonForAdditionalLaborHours>
</eachJobCode>
</jobCodesType>
<usageMetersType>
<!--1 or more repetitions:-->
<eachUsageMeter>
<usageAmount>1661</usageAmount>
<usageType>HoursInService</usageType>
<usageUOM>HOURS</usageUOM>
</eachUsageMeter>
</usageMetersType>
</SubmitClaimRequest>
</get:getSubmitClaim>
</soapenv:Body>
</soapenv:Envelope>
如何在C#代码中调用复杂类型方法将请求发送给外部公司?或者使用C#手动创建XML文件更容易?
更新代码:
using (var client = new getSubmitClaimWSD_PortTypeClient())
{
SubmitClaimRequest request = new SubmitClaimRequest()
{
buName = "Thermo King TSA",
dealerNumber = "PHSDF",
userName = "Roger",
password = "1234",
transactionType = "WARRANTY",
claimLanguage = "ENG",
serviceVersion = "1.0",
claimType = "PARTS",
failureDate = new DateTime(2014, 11, 26),
faultFound = "PERFORM A FREE INSPECTION",
inventorySerialNumber = "12352341",
repairDate = new DateTime(2014, 11, 26),
workOrderNumber = "testProcede1",
conditionsFound = "test",
workPerformed = "test",
claimNotes = "test claim notes",
faultLocation = "FF",
failureDetail = "test",
smrClaim = "N",
forceToDraft = "Y",
validateOnly = "N",
commercialPolicy = "N",
fuelSurcharge = 0,
shopSupplies = 0,
claimCurrency = "USD",
workOrderSegment = "1",
partsType = new[]
{
new eachPart() {partNumber = "1234", partPrice = 100.78, partQuantity = 17, partType = "NONIR", partDescription = "test part desc"},
new eachPart() {partNumber = "5678", partPrice = 200.90, partQuantity = 1, partType = "IRREMOVED", partDescription = "test part desc 2"}
}
};
var response = client.getSubmitClaim(null, request);
var rsp = response.response;
Console.WriteLine("Status {0}, claim {1}; {2} {3}, {4} errors", rsp.status, rsp.claimNumber,
rsp.workOrderNumber, rsp.workOrderSegment, rsp.errorsType.Length);
}
答案 0 :(得分:1)
尝试这样的事情:
using (var client = new SubmitClaimService.getSubmitClaimWSD_PortTypeClient())
{
SubmitClaimRequest request = new SubmitClaimRequest()
{
claimLanguage = "ENG",
serviceVersion = "1.0",
claimType = "PARTS",
failureDate = new DateTime(2014, 11, 26),
faultFound = "PERFORM A FREE INSPECTION",
partsType =
new[]
{
new eachPart() {partNumber = "1234", partPrice = 100.78, partQuantity = 17},
new eachPart() {partNumber = "5678", partPrice = 200.90, partQuantity = 1}
}
};
submitClaimResponse response = client.getSubmitClaim(request);
var rsp = response.response;
Console.WriteLine("Status {0}, claim {1}; {2} {3}, {4} errors", rsp.status, rsp.claimNumber,
rsp.workOrderNumber, rsp.workOrderSegment, rsp.errorsType.Length);
}
我通过右键单击服务引用并选择&#34;在对象浏览器中查看&#34;来解决这个问题。或者,您可以使用View-&gt; Object Browser启动对象浏览器,然后导航到服务引用。