我正在使用内置的Web服务参考客户端与第三方Web服务进行通信。
工作流程包括连续拨打3个电话。第一个调用工作正常,但是第二个调用返回空对象,即使消息包含请求的数据也是如此。我很好奇它是否是某种模式不匹配导致的,或者它是否是我的代码中的错误。
这是问题部分的wsdl。
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
<table class="table table-striped- table-bordered">
<thead>
<tr>
<td>ID</td>
<td>Number</td>
</tr>
</thead>
<tbody id="TableBody">
<tr>
<td>IRD-1</td>
<td class="number" contenteditable>9</td>
</tr>
<tr>
<td>IRD-2</td>
<td class="number" contenteditable>10</td>
</tr>
</tbody>
</table>
响应
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="scheduler.redwood.com" targetNamespace="scheduler.redwood.com">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="scheduler.redwood.com">
<s:complexType name="ArrayOfJobField">
<s:sequence>
<s:element name="JobField" type="s:string" minOccurs="0" maxOccurs="unbounded" nillable="false" />
</s:sequence>
</s:complexType>
<s:complexType name="QueryJobRequest">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="JobId" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="JobFields" type="tns:ArrayOfJobField" />
</s:sequence>
</s:complexType>
<s:complexType name="JobFieldValue">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Name" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="Type" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="Value" type="s:string" />
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfJobFieldValue">
<s:sequence>
<s:element name="JobFieldValue" type="tns:JobFieldValue" minOccurs="0" maxOccurs="unbounded" nillable="false" />
</s:sequence>
</s:complexType>
<s:complexType name="JobParameterValue">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Name" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="Type" type="s:string" />
<s:element minOccurs="0" maxOccurs="unbounded" name="InValue" type="s:string" />
<s:element minOccurs="0" maxOccurs="unbounded" name="OutValue" type="s:string" />
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfJobParameterValue">
<s:sequence>
<s:element name="JobParameterValue" type="tns:JobParameterValue" minOccurs="0" maxOccurs="unbounded" nillable="false" />
</s:sequence>
</s:complexType>
<s:complexType name="QueryJobResult">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Status" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="Description" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="JobParameters" type="tns:ArrayOfJobParameterValue" />
<s:element minOccurs="1" maxOccurs="1" name="JobFields" type="tns:ArrayOfJobFieldValue" />
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="QueryJobIn">
<wsdl:part name="QueryJobRequest" type="tns:QueryJobRequest" />
</wsdl:message>
<wsdl:message name="QueryJobOut">
<wsdl:part name="QueryJobResult" type="tns:QueryJobResult" />
</wsdl:message>
<wsdl:portType name="QueryJobPortType">
<wsdl:operation name="QueryJob1">
<wsdl:documentation />
<wsdl:input message="tns:QueryJobIn" />
<wsdl:output message="tns:QueryJobOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="QueryJobBinding" type="tns:QueryJobPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="QueryJob1">
<soap:operation soapAction="query/Job/QueryJob1" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="QueryJobService">
<wsdl:port binding="tns:QueryJobBinding" name="QueryJobPortType">
<soap:address location="https://xxx/api-soap/query/Job/QueryJob1" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
这是呼叫代码
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:job="scheduler.redwood.com">
<soapenv:Header />
<soapenv:Body>
<job:QueryJobResult>
<job:Status>Completed</job:Status>
<job:Description>Submitted via web service xxxx</job:Description>
<job:JobParameters>
<job:JobParameterValue>
<job:Name>OutputFormat</job:Name>
<job:Type>String</job:Type>
<job:InValue>XMLText</job:InValue>
</job:JobParameterValue>
<job:JobParameterValue>
<job:Name>ReportLimit</job:Name>
<job:Type>Number</job:Type>
<job:InValue>2147483647</job:InValue>
</job:JobParameterValue>
<job:JobParameterValue>
<job:Name>RecordCount</job:Name>
<job:Type>Number</job:Type>
<job:OutValue>36</job:OutValue>
</job:JobParameterValue>
</job:JobParameters>
<job:JobFields>
<job:JobFieldValue>
<job:Name>Status</job:Name>
<job:Type>Job.Status</job:Type>
<job:Value>Completed</job:Value>
</job:JobFieldValue>
<job:JobFieldValue>
<job:Name>Queue</job:Name>
<job:Type>Job.Queue</job:Type>
<job:Value>xxx</job:Value>
</job:JobFieldValue>
</job:JobFields>
</job:QueryJobResult>
</soapenv:Body>
</soapenv:Envelope>
根据我在某处遇到的一些调试建议,我注册了一个IClientMessageInspector,然后输入
private void WaitForJob(string user, string password, string jobId)
{
RMJQueryJob1.QueryJobPortTypeClient client = new RMJQueryJob1.QueryJobPortTypeClient();
client.Endpoint.EndpointBehaviors.Add(new FaultFormatingBehavior());
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.UserName.UserName = user;
client.ClientCredentials.UserName.Password = password;
using (System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope(client.InnerChannel))
{
var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " +
Convert.ToBase64String(Encoding.ASCII.GetBytes(client.ClientCredentials.UserName.UserName + ":" +
client.ClientCredentials.UserName.Password));
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
RMJQueryJob1.QueryJobRequest queryJobRequest = new RMJQueryJob1.QueryJobRequest();
queryJobRequest.JobId = jobId;
queryJobRequest.JobFields = new string[] { "Status", "Queue" };
// THIS RETURNS NULL
var result = client.QueryJob1(queryJobRequest);
}
}
我可以在回复中看到上面列出的响应正文。